Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react class 组件使用 shouldComponentDidUpdate 优化组件 #42

Open
gaowei1012 opened this issue Sep 29, 2020 · 0 comments
Open

react class 组件使用 shouldComponentDidUpdate 优化组件 #42

gaowei1012 opened this issue Sep 29, 2020 · 0 comments

Comments

@gaowei1012
Copy link
Owner

react 项目中,使用 shouldComponentDidUpdate(nextProps, nextState){}优化页面

shouldComponentDidUpdate 接收两个参数 nextProps & nextState,分别监听组件的下一次 props & state 变化时,渲染我们页面,(只有在其返回 true的情况下才会生效)

shouldComponentDidUpdate(nextProps, nextState) { 

if (nextState !== this.state.list) {
   return false; 
}

return true;
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant