React Against DOM Confusion Reaction

I am using ES6 babel with a response, and now for a newer version react, the DOM is no longer part of this. My doubt about the code below is what is the first line required? since I don’t need React anywhere, but the last line I need ReactDOM.

const React = require('react') const ReactDOM = require('react-dom') const App = () => { return ( <div className='app-container'> <div className='home-info'> <h1 className='title'>sVideo</h1> <input className='search' type='text' placeholder='Search' /> <button className='browse-all'> or Browse All</button> </div> </div> ) } ReactDOM.render(<App />, document.getElementById('app')) 
+6
source share
3 answers

React from version 0.14 further divided into two parts: React and ReactDOM. . You are using ReactDOM to render you HTML element . Therefore, it definitely makes sense for you to import ReactDOM in your Component. But as for React, although you are not using React directly, it is indirectly used, because everything you write in your function return statement will be transpiled into React.createElement , which will create the actual DOM elements.

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

no reaction

and this will give you that React is not recognised in React.createElement. I hope you understand this.

+9
source

From ReactDOM :

This package serves as the entry point to the associated paths associated with the DOM. It is designed to interface with an isomorphic reagent that will be sent in reaction with npm.

So, your ReactDOM specifically designed for DOM related paths for rendering. This was closely related to the React package, but the built-in DOM in React became obsolete.

Now Facebook sends ReactDOM separately as its own package, so yes, you need to include it in your application if you plan to render any of your actions. And you also definitely need React itself - ReactDOM is just the DOM side.


Here's a reddit post explaining the separation from React and ReactDOM .

The React team is working on extracting all DOM-related material into a separate library called ReactDOM. 0.14 is the first release in which libraries are shared.

A bit funny fact, since they want to maintain backward compatibility, they kept the React internal DOM, but did not allow people to use it in a funny way .

+1
source

They are separate from version 0.14 and for any response project you need to enable both parameters: ReactDOM lies on React and React , without ReactDOM the DOM cannot be passed, so the answer is big Yes !

0
source

All Articles