1

I am building a React application using the create-react-app. My application will rely on an API for initial HTML using which I will hydrate my app and add React components to it dynamically during load and serve to the browser.

I planned to call the API in componentDidMount() of the initial app component and replace the static HTML with the dynamic one from the API using ReactDOM.render(element, document) I can replace the whole DOM (including <html></html>).

Is there any other approach which doesn't have a dirty path like this, or is there any other best practices for doing something like this?

4

1 回答 1

0

如果你在后端使用 React,那么ReactDOM.hydrate从 React 16 开始就可以使用。

否则,最好在第一次调用ReactDOM.render.

于 2018-03-13T10:40:08.247 回答