javascript - 更改应用状态后清除存储数据
问题描述
我是 React-Native 新手。我按照反应导航文档中的代码来处理语言更改事件。但是,在我的屏幕上调用该函数后,所有setLocale
应用商店(redux-store)都被清除了,我不知道为什么?下面是this.props.screenProps.setLocale(locale)
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;
}
解决方案
推荐阅读
- postgresql - 插入冲突时增加字段数
- node.js - Puppeteer 搞砸了 PDF 渲染
- python - Python:如何将字符串格式的(utf-8)字节数组对象解码回字符串?
- sanity - 如何在 Sanity.io 中自定义字符串?(自动填充)
- python - 如何将 git 中 __init__.py 的内容(并维护历史记录)传输到另一个文件,同时仍然保持空的 __init__.py
- python - 每个循环按顺序初始化一个新列表以保存不同的值
- flutter - 如何在列表视图中制作标签栏和标签栏视图?
- rust - it is possible to turn a seft-owned variable to static lifetime?
- javascript - 制作适合多人游戏的画布视口
- javascript - 获取 TypeError:jquery__WEBPACK_IMPORTED_MODULE_1___default(...)(...).fancybox 不是函数