no message
This commit is contained in:
+2
-2
@@ -57,8 +57,8 @@
|
||||
return "getSnapshotBeforeUpdate"
|
||||
}
|
||||
componentDidUpdate(preProps,preState,snapshotValue){
|
||||
console.log(snapshotValue)
|
||||
// console.log(preProps,preState)
|
||||
// console.log(snapshotValue)
|
||||
console.log(preProps,preState)
|
||||
// console.log('componentDidUpdate')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,24 @@ class Child extends React.Component{
|
||||
componentDidMount() {
|
||||
console.log('componentDidMount');
|
||||
}
|
||||
componentDidUpdate() {
|
||||
console.log('componentDidUpdate');
|
||||
shouldComponentUpdate(){
|
||||
console.log('shouldComponentUpdate')
|
||||
return true
|
||||
}
|
||||
getSnapshotBeforeUpdate(prevProps,prevState){
|
||||
console.log(prevState)
|
||||
return "getSnapshotBeforeUpdate"
|
||||
}
|
||||
componentDidUpdate(preProps,preState,snapshotValue) {
|
||||
console.log(preProps,preState,snapshotValue);
|
||||
}
|
||||
// 劫持state
|
||||
// state属性与props相关时
|
||||
static getDerivedStateFromProps(props,state){
|
||||
console.log("getDerivedStateFromProps")
|
||||
// return {count:"xxx"}
|
||||
return null;
|
||||
}
|
||||
console.log("getDerivedStateFromProps")
|
||||
// return {count:"xxx"}
|
||||
return null;
|
||||
}
|
||||
add=()=>{
|
||||
let {count}=this.state;
|
||||
count+=1;
|
||||
@@ -24,7 +32,7 @@ class Child extends React.Component{
|
||||
return (
|
||||
<div>
|
||||
<h1>子组件</h1>
|
||||
<h3>state:{this.state.count}</h3>
|
||||
{/* <h3>state:{this.state.count}</h3> */}
|
||||
<h3>props:{this.props.name}</h3>
|
||||
<button onClick={this.add}>子组件点击事件</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user