使用旧值进行React渲染

时间:2016-07-31 22:33:53

标签: javascript reactjs

我正在React中更新我的应用程序状态,我看到Render方法是用旧状态处理的。需要做什么才能使React呈现新状态?

基本上我有和Ajax调用,如果有更新或者被跳过,可以调用它。如果跳过ajax调用并且已使用现有数据,则React不会更新状态。

 this.setState({
        errorStr: null,
        isSubmitting: false,
        isLoading: false
    });

在Render方法的console.log输出中,我看到isSubmitting仍然是真的。因此,更新永远不会呈现。

由于

1 个答案:

答案 0 :(得分:0)

研究此链接componentWillMount()和componentDidMount()。使用这种方法之一,然后你的问题将得到解决

https://facebook.github.io/react/docs/component-specs.html