目前我必须重新配置我的商店才能创建选择器。有没有更好的方法来做到这一点。
import { configureStore } from "../configureStore";
const { store } = configureStore();
export const getSession = () => store.getState().session.data || false;
export const getToken = () => store.getState().session.data.token || false;
最佳答案
选择器函数应将存储状态作为参数,而不是捕获存储引用。举个例子:
export const getSession = (state) => state.session.data || false;
export const getToken = (state) => state.session.data.token || false;
// use like:
const session = getSession(store.getState());
查看我的帖子Idiomatic Redux: Using Reselect Selectors for Encapsulation and Performance了解更多详情。
关于javascript - 提取 Redux Store/State 作为选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54078879/