反应本机检查以前的状态 [英] react native checking previous state

查看:44
本文介绍了反应本机检查以前的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在渲染中检查先前状态的值

I cant check a value of a previous state in render

我的代码是

    this.setState(previousState => ({
  if(name!=previousState.name){

                 name:name,
                uri:uri,
                fbid:fbid,


 }           
        }));

推荐答案

有一个组件生命周期方法,componentWillUpdate,您可以通过它来检查当前状态和新状态.当 props 或 state 改变时,它总是被调用.例如:

There is a component lifecycle method,componentWillUpdate by which you can check the current and the new state. It is always called when the props or state changes. For example:

componentWillUpdate(nextProps, nextState) {
  console.log(nextState); //will show the new state
  console.log(this.state); //will show the previous state
}

如需参考,请访问:componentWillUpdate

这篇关于反应本机检查以前的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆