react best practice (3)-- learning source code
Try to setup react soure code learning environment.
1. Step 1
1 | git clone https://github.com/facebook/react.git |
According the How to contribute, next run command below
1 | yarn build react/index,react-dom/index --type=UMD |
Using yarn create react-app to create a new project and remove dependency of react and react-dom in package.json
1 | yarn create react-app react-source-learning --template:typescript |
2. Step 2
Write JSX in maunally.
1 | import React from 'react'; |
We can go to Babel to check the
elementmentioned above.elementis equal toelement2.
The process is:
1, JSX will be transferd to React.createElement method by Babel
2, React.createElement is actually returned a virtual node.
3, React.Render will render the virtual node to realistic dom
So next to implement a createElement in react.js.
And then to create a new react-dom.js