diff --git a/basic/6/P06.html b/basic/6/P06.html index c67e25727..f71735bbd 100644 --- a/basic/6/P06.html +++ b/basic/6/P06.html @@ -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') } } diff --git a/chenxuan1/src/pages/life.jsx b/chenxuan1/src/pages/life.jsx index efeddf61f..03b9cf143 100644 --- a/chenxuan1/src/pages/life.jsx +++ b/chenxuan1/src/pages/life.jsx @@ -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 (