reactjs - 在非 React 组件中访问 React persistStore
问题描述
你能帮我了解如何访问 Redux 持久存储非反应组件吗?Store.js 和非反应组件如下 -
Store.js
const persistedReducer = persistReducer(persistConfig, rootReducer);
function configureStore(initialState) {
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
persistedReducer,
initialState,
bindMiddleware([sagaMiddleware])
);
store.sagaTask = sagaMiddleware.run(rootSaga);
return store;
}
export default configureStore;
非反应成分 -
export const customHeaders = {
Accept: 'application/json',
Authorization: authorization_prefix + token //i want to access the token here from the above persist store.
};
export default axios.create({
baseUrl,
headers: customHeaders,
});
我尝试了下面的代码,但它没有用
import configureStore from 'path to configureStore'
const { store } = configureStore();
console.log(store.getState()); //Error : TypeError: Object(...) is not a function
解决方案
推荐阅读
- android - 我们可以使用 appium 通过自动化脚本更改 android 移动设备的日期和时间吗?
- python - 改变 x、y 轴改变 Matplotlib 散布气泡
- python - 如何使用 docker buildx bake 为 linux/armv7 和 linux/amd64 构建 docker compose 容器
- java - 如何正确读取和写入 ByteBuffer?
- python - django 配置 apache 来提供媒体和静态文件
- performance - 大 O 复杂度:T(n) = O(f(n)),G(n) = O(h(n))。T(G(n)) = O(h(f(n)))?
- firebase - Firebase RTDB 负载均衡与云功能
- qt - Linux 与 Windows 的部署规模
- php - 使用 composer 替换 Laravel 中的库自动加载源
- random - 如何将此代码转换为扫描随机数据而不是分箱数据?