Home > Article > Web Front-end > What is the difference between react and reactdom
The difference between react and reactdom is: ReactDom only does operations related to the browser or DOM, such as the "ReactDOM.findDOMNode()" operation; while react is responsible for related operations other than the browser and DOM, and ReactDom is Part of React.
The operating environment of this tutorial: Windows 10 system, react17.0.1 version, Dell G3 computer.
ReactDom only does operations related to the browser or DOM, such as: ReactDOM.render() and ReactDOM.findDOMNode(). If it is server-side rendering, you can use ReactDOM.renderToString(). React can not only deal with web pages through ReactDOM, but can also be used in server-side SSR, mobile-side ReactNative and desktop-side Electron.
React did not have ReactDOM before v0.14, and all functions were included in React. Starting from v0.14 (2015-10), React was split into React and ReactDOM. Why separate React and ReactDOM? Because of ReactNative. React only contains the core parts common to Web and Mobile. Those responsible for DOM operations are divided into ReactDOM, and those responsible for Mobile are included in ReactNative.
ReactDom is part of React. ReactDOM is the glue between React and DOM. It is generally used to define a single component, or used in conjunction with ReactDOM.findDOMNode(). What's more, the ReactDOM package already allows developers to remove non-essential code added by the React package and move it to a more suitable repository.
e.g:
Web side React code
import React from 'react'; import ReactDOM from 'react-dom'; const App = () => ( <div> <h1>Hello React</h1> </div> ) ReactDom.render(<App/>, document.getElementById('root'));
Mobile side ReactNative code:
import React from 'react'; import {Text, View} from 'react-native'; const WelcomeScreen = () => ( <View> <Text>Hello ReactNative</Text> </View> );
The same thing is that they all need to import React from 'react'.
And Web applications need to import ReactDOM from 'react-dom';
Mobile applications need to import {Text, View} from 'react-native'
Recommended learning: " react video tutorial》
The above is the detailed content of What is the difference between react and reactdom. For more information, please follow other related articles on the PHP Chinese website!