react vs react DOM confusion

前端 未结 4 801
-上瘾入骨i
-上瘾入骨i 2020-12-17 20:29

I\'m using ES6 babel with react, and now for the newer version react, react DOM is not a part of it anymore. My doubt for below code is that, is it the first line require? s

4条回答
  •  一个人的身影
    2020-12-17 21:31

    React from version 0.14 onwards is split into two parts: React and ReactDOM. You are making use of ReactDOM to render you HTML element. So it definitely makes sense for you to import ReactDOM in your Component. But as far as React is concerned although you are not making use of React directly but it is indirectly being used because whatever you write in your return statement will be transpiled into React.createElement function that will create the actual DOM elements.

    Now you can see this if you omit React in your code, you will see an error that

    react is not present

    and it will give you that React is not recognised in React.createElement. Hope you understood it.

提交回复
热议问题