React學習手冊-Component元件
Mounting/Updating/Unmounting/Error Handling
These methods are called in the following order when an instance of a component is being created and inserted into the DOM:
- constructor()
- static getDerivedStateFromProps()
- render()
- componentDidMount()
class X is a React.Component
Import
import React, { Component } from 'react';
Inheritance
class X extends Component
const X = ()=>{ //return <h1>Hello world !!!</h1> }
Instancing
<X value={...} />
Prototype
constructor(props) {
super(props);
this.state = {
value: null,
};
}
render() {
return (
//...
);
}
// This gets linted
var answer = 6 * 7;
console.log(answer);
// This also gets linted
/* eslint quotes: [2, "double"] */
function hello() {
console.log("Hello, world!");
}
hello();
// This gets linted too
var div = <div className="jsx"></div>;
// And this
console.log(process.version);
This is plain text and doesn't get linted.