为什么 redux 多重初始化

Why redux multiple initializing

Must be like that

But this type going to new redux instance

如果我超时调用操作没问题。

  componentDidMount(){
    setTimeout(()=>this.props.isLoggedIn(), 100)
  }

或者如果我在渲染下调用,就没问题了。

  render() {
    this.props.isLoggedIn()
    ...
    ...

仅当我在应用程序加载时调用 componentDidUpdate 下的操作时才会出现此问题。像那样:

  componentDidMount(){
    this.props.isLoggedIn() //problem
  }

导致拆分 redux 实例...

好的,我找到问题了。有趣的是我错误地使用了 createStore 函数。

我在调用 render()

  render() {
    const store = createStore(reducers, composeWithDevTools(applyMiddleware(ReduxThunk)))
    ...
    ...

现在我移出顶部,问题解决了。

const store = createStore(reducers, {}, applyMiddleware(ReduxThunk))

export default class App extends React.Component {
  render() {
    return (
      <Provider store={store}>
        ...
        ...