- What is the difference between the render() function from react-dom and the renderToString() function from react-dom/server?
- The render() function is only used to sync React component content with the DOM in a browser. The renderToString() function doesn't require a DOM because it renders markup as a string.
- The two functions are interchangeable.
- The render() function is slower on the server so renderToString() is a better option.
- You should only use render() in the browser if you have to. The renderToString() function is preferable in most cases.
- Routing on the server is necessary because:
- Without routing on the server, there's no way to actually render components.
- You don't need to worry about rendering on the server since the routes will be handled in the browser.
- The router on the server will determine that content is rendered based on the requested URL. This content is then sent to the browser so that the user perceives a faster load time.
- Routing on the server should be down manually instead of using components from react-router.
- What function should you use when reconciling server-rendered React markup with React components in the browser?
- Always use render() in the browser. It knows how to make changes to existing markup that are necessary.
- Always use hydrate() when the server sends rendered React components. Unlike render(), hydrate() expects rendered component markup and can handle it efficiently.