【问题标题】:Why redux multiple initializing为什么 redux 多次初始化
【发布时间】:2020-03-12 15:41:44
【问题描述】:

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实例...

【问题讨论】:

    标签: reactjs react-native react-redux redux-thunk react-native-debugger


    【解决方案1】:

    好的,我发现了问题。有趣的是我错误地使用了 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}>
            ...
            ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      相关资源
      最近更新 更多