componentWillMount和componentDidMount之间会发生什么?

时间:2019-11-30 15:07:42

标签: reactjs react-native

我在componentDidMount中使用全局变量来设置状态。但是全局变量的值正在清空。

代码:

componentWillMount () {
   console.log(JSON.stringify(global.variable)) //The value of the variable is intact
}

componentDidMount () {
    console.log(JSON.stringify(global.variable)) //The value of the variable is empty
    mqttFunction() {
       ...
       // telemetry updates and redux store actions
    }
}

这是怎么回事?我在这里错过了什么吗?

0 个答案:

没有答案
相关问题