no message

This commit is contained in:
chenxuan
2024-04-19 14:28:35 +08:00
parent f5f5f7b0f9
commit e50a8abb91
2 changed files with 17 additions and 9 deletions
+2 -2
View File
@@ -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')
}
}
+15 -7
View File
@@ -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>