我在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
}
}
这是怎么回事?我在这里错过了什么吗?