Home > Article > Web Front-end > How to view react source code
How to view the react source code: 1. Enter the react official website; 2. Download the packages file locally; 3. Open the index.js file, which is the entry file of the react source code. We can also convert react source code through babel.
The operating environment of this tutorial: windows10 system, react16 version. This method is suitable for all brands of computers.
(Learning video sharing: react video tutorial)
The specific method is as follows:
1. Enter the official website
https://github.com/facebook/react
2. The source codes are all in the packages file
https://github.com/facebook/react/tree/master/packages
3. You can download the file locally, which will look more convenient
4. Then enter the pageages/react/index.js file, this file It is the entrance to the react source code
5. This URL can display the react code as the code converted by babel
https://react.docschina.org/
Example:
import React, { Component } from "react"; import ReactDOM from "react-dom"; import "./index.css"; function FuncCmp(props) { return <div>name: {props.name}</div>; } class ClassCmp extends Component { render() { return <div>name: {this.props.name}</div>; } } const jsx = ( <div> <p>我是内容</p> <FuncCmp name="我是function组件" /> <ClassCmp name="我是class组件" /> </div> ); ReactDOM.render(jsx, document.getElementById("root"));
After compiled by babel:
function FuncCmp(props) { return React.createElement( "div", null, "name: ", props.name ); } class ClassCmp extends React.Component { render() { return React.createElement( "div", null, "name: ", this.props.name ); } } let jsx = React.createElement( "div", null, " ", React.createElement( "div", { className: "border" }, "我是内容" ), " ", React.createElement(FuncCmp, { name: "我是function组件" }), " ", React.createElement(ClassCmp, { name: "我是class组件" }), " " ); ReactDOM.render(jsx, document.getElementById('root'));
Related recommendations: js tutorial
The above is the detailed content of How to view react source code. For more information, please follow other related articles on the PHP Chinese website!