反应store.subscribe setState警告

时间:2017-03-28 02:24:25

标签: reactjs react-native react-router react-redux

我尝试在商店数据发生变化时更新状态。我在componentDidMount上订阅并取消订阅componentWillUnmount,如下所示:

componentDidMount() {   
const { store } = this.context
this.unsubscribe = store.subscribe(() => {      
this.setState({ 
skillsValue: store.getState().admin.userProfile.seeker.skillsValue || [],
...
componentWillUnmount()
{
this.unsubscribe
}

然而,我收到了这个警告。

警告:setState(...):只能更新已安装或安装的组件。这通常意味着您在已卸载的组件上调用了setState()。这是一个无操作。请检查xxxx组件的代码。

1 个答案:

答案 0 :(得分:0)

我有类似的问题,我用过:

setTimeout(this.setState(...), 0)

说明:

相关问题