Concept: The contents of the tag assembly between open and closed assembly inside the tag display on display, by passing prop. (Parent components define the content of the sub-assembly, similar to the slot vue slot)
form
Inclusion relation
Rendering Other components
//父组件
import ChildA from './childA.jsx'
class Father extends Component {
state = {}
render(){
let Acom = <a href="#">这是一个a标签组件</a>
return <div className="extend-father" style={{border:'1px solid #000'}}>
father content
<ChildA Acom={Acom}>
<h1>包含关系:嵌入内容</h1>
</ChildA>
</div>
}
}
// 子组件
class ChildA extends Component {
constructor(props){
super(props)
this.state = {}
}
render(){
return <div style={{backgroundColor:'orange'}}>
hello world!
{/* 包含关系 */}
{this.props.children}
{/* 渲染其他组件 */}
{this.props.Acom}
</div>
}
}
Second, the error handling border
Concept: Error border is actually a component that can capture and print the javascript error occurred in its subcomponents tree anywhere, and he will render spare ui.
Concept: high-order component (HOC) is a logic component reuse react in advanced technology, but not the higher-order component itself React API, which is only a model that is produced by a combination of properties itself react inevitable .
effect
Public extract business logic, taking
Rendering hijacking
Use: passing a higher-order function component, a new component returns after treatment
Providing more logical operations for the functional components dieting
You can use state in the case of the preparation of class
Why
Resolve the difficulties before taking the state logic components
Reduce the cost of learning react in the use of class
Can be combined perfectly with clas components
Embrace become functional
Solve the problem of difficult to understand the life cycle
useState
Any type of support incoming data as an initial value
It returns an array having two parameters
The first parameter data for the monitor data values, corresponding to the defined state
The second parameter is a function of changing data corresponding to the setState, but does not merge state
Inert support job, execution useState parameters when using (change is not executed)
It can be used several times in a functional component
useEffect
Side effects hook function
Instead componentDidMount, componentDidUpdate and componentWillUnmount lifecycle methods
Access to props and state
To clear the side effects by returning a function
The second parameter may specify dependencies, dependency can be specified by a plurality of array, if the equivalent of an empty array componentDidMount
Custom Hooks understood: that is encapsulated into a common logical function to extract class to obtain the desired content by passing in a callback Demo: obtaining a current timestamp of the package common logical
useEffect after the render, it will execute the callback function, and does not block the browser rendering (asynchronous operation .ps: class components componentDidMount and componentDidUpdate are synchronized)
Completed before useLayoutEffect it is when you need to do inside the callback dom operation, he will execute the callback function immediately, but will be drawn in any browser