我将访问 token 存储在 Redux 存储中,我想将它与每个需要身份验证的 API 请求一起发送。我有一个 API 函数类。这是一种图书馆。我不确定如何从 API 类访问 token 。
有人可以帮忙吗?
最佳答案
你必须在你需要从各自的索引文件访问商店的文件中导入商店,我已经这样做了
import { store } from '../index';
store.subscribe(() => {
store.getState();
token = store.getState().Login.token; //access token here
})
在 index.android.js/index.ios.js 中我导出了 store
export const store = createStore(
RootReducer,
undefined,
// the ordering of middleware is significant.
applyMiddleware(thunk),
);
关于reactjs - 如何从辅助类或函数访问 redux 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48804008/