【问题标题】:How to update state in App.js upon completion of store rehydration?商店补水完成后如何更新 App.js 中的状态?
【发布时间】:2019-07-15 01:06:37
【问题描述】:

我有一个非常标准的样板文件。基本上我实现了 Redux-persist 并渲染加载屏幕,直到商店被补水。

Store.js

const store = Reactotron.createStore(
  reducers,
  undefined,
  compose(
    applyMiddleware(ReduxThunk),
    offline({
      ...offlineConfig,
      persistCallback: () => Reactotron.log('HEY LOADED') //<<====How to update rehydrated state in App.js
    })
  )
);

App.js

import store from './Store';

export default class App extends Component {
  state = { rehydrated: false };

  ...

  render() {
    if (!this.state.rehydrated) return <Loading />

    return (
      <Provider store={store}>
        <MainNavigator />
      </Provider>
    )
  }

基于上述设置,我可以看到商店重新水化成功后的日志记录。但是我想知道它如何更新 App.js 的状态?

【问题讨论】:

    标签: javascript reactjs react-native redux redux-persist


    【解决方案1】:

    您可以实现PersistGate 以显示加载屏幕,直到您的持久状态被检索到。如这里第二部分所述,https://github.com/rt2zz/redux-persist#basic-usage

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      • 2020-12-18
      • 2022-06-21
      • 1970-01-01
      • 2016-12-18
      • 2017-01-01
      • 1970-01-01
      相关资源
      最近更新 更多