React vs ReactDOM?

后端 未结 9 1032
野性不改
野性不改 2020-11-30 18:02

I\'m a bit new to react. I see we have to import two things to get started, React and ReactDOM, can anyone explain the difference. I\'m reading thr

9条回答
  •  渐次进展
    2020-11-30 18:41

    From the React v0.14 Beta release announcement.

    As we look at packages like react-native, react-art, react-canvas, and react-three, it's become clear that the beauty and essence of React has nothing to do with browsers or the DOM.

    To make this more clear and to make it easier to build more environments that React can render to, we're splitting the main react package into two: react and react-dom.

    Fundamentally, the idea of React has nothing to do with browsers, they just happen to be one of many targets for rendering trees of components into. The ReactDOM package has allowed the developers to remove any non-essential code from the React package and move it into a more appropriate repository.

    The react package contains React.createElement, React.createClass and React.Component, React.PropTypes, React.Children, and the other helpers related to elements and component classes. We think of these as the isomorphic or universal helpers that you need to build components.

    The react-dom package contains ReactDOM.render, ReactDOM.unmountComponentAtNode, and ReactDOM.findDOMNode, and in react-dom/server we have server-side rendering support with ReactDOMServer.renderToString and ReactDOMServer.renderToStaticMarkup.

    These two paragraphs explain where the core API methods from v0.13 ended up.

提交回复
热议问题