React vs ReactDOM?

后端 未结 9 1031
野性不改
野性不改 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:26

    Before v0.14 they were part of main ReactJs file, but as in some cases we may not need both, they separate them and it starts from version 0.14, that way if we need only one of them, our app gonna be smaller due to using only one of those:

    var React = require('react'); /* importing react */
    var ReactDOM = require('react-dom'); /* importing react-dom */
    
    var MyComponent = React.createClass({
      render: function() {
        return 
    Hello World
    ; } }); ReactDOM.render(, node);

    React package contains: React.createElement, React.createClass, React.Component, React.PropTypes, React.Children

    React-dom package contains: ReactDOM.render, ReactDOM.unmountComponentAtNode, ReactDOM.findDOMNode, and react-dom/server that's including: ReactDOMServer.renderToString and ReactDOMServer.renderToStaticMarkup.

提交回复
热议问题