更改应用状态后清除存储数据

我是React-Native的新手。 我按照code from react navigation docs处理语言更改事件。但是,在屏幕上由setLocale调用函数this.props.screenProps.setLocale(locale)之后,App'商店(redux-store)的所有state被清除了,我不知道为什么吗?以下是App.js

type State = {
  locale: string,};
type Props = {};
class App extends React.Component<Props,State> {
  constructor(props) {
    super(props);
    // default i18n.locale = 'en'
    this.state = {locale: i18n.locale};
  }

  setLocale = (locale: string) => {
    this.setState({locale});
  };

  t = (scope: string,options: any) => {
    return i18n.t(scope,{locale: this.state.locale,...options});
  };

  render() {
    const screenProps = {
      t: this.t,locale: this.state.locale,setLocale: this.setLocale,};

    return (
      <Provider store={configureStore()}>
        <ThemeProvider>
          <AppContainer screenProps={screenProps} />
        </ThemeProvider>
      </Provider>
    );
  }
}

export default App;

我的configueStore()

export default function configureStore(initialState = {}) {

  const sagaMiddleware = createSagaMiddleware();

  const composeEnhancers =
    typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION__
      ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
      : compose;

  const enhancer = composeEnhancers(
    applyMiddleware(sagaMiddleware),);

  const store = createStore(rootReducer,enhancer);

  sagaMiddleware.run(rootSaga);
  return store;
}
cxd345 回答:更改应用状态后清除存储数据

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3139097.html

大家都在问