例如在App.js
中我有
let store = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));
export { store }
当我在另一个文件中 import { store as mainStore } from './App'
时,我认为它将在成为 mainStore 之前运行
。我可以重新导入以便稍后再次运行此代码吗?对于本例,我确实想在测试之间重置 createStore
store
变量的状态。 createStore
方法就可以做到这一点。
最佳答案
For this instance I do want to reset the store variable's state in between tests. And the createStore method can do just that.
解决方案1:
如果你想重置存储变量,那么在 redux 中你可以 dispatch action 并将特定的存储值设置为您想要的任何值
解决方案 2: 怀疑未满
创建不同的商店变量,例如
导出 const store1 = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));
导出 const store2 = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));
关于javascript - 我可以在 Javascript 中再次导入吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42921146/