0%
ReactDOM.render的改变
挂载dom的改变
1 2 3 4 5 6 7 8 9 10 11
| import * as ReactDOM from 'react-dom'; import App from 'App';
const container = document.getElementById('app');
- ReactDOM.render(<App />, container);
+ const root = ReactDOM.createRoot(container); + root.render(<App />);
|
渲染回调的改变
React 17
通过给 render 传递一个回调函数,在组件被渲染或更新后调用;
React 18
通过App 的 props传入回调函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| import * as ReactDOM from 'react-dom'; import App from 'App';
const container = document.getElementById('app');
ReactDOM.render(container, <App tab="home" />, function() { console.log('rendered'). });
const root = ReactDOM.createRoot(container); root.render(<App callback={() => console.log("renderered")} />);
|