【发布时间】:2019-05-12 21:50:57
【问题描述】:
我想从后端(即showTutorial)获取一些变量,用于reducer 中的初始状态。
我在考虑只使用 reducer 在 axios 中的调用,但我不确定这是否是最好的方法。
现在是这样完成的:
import { UNSET_TUTORIAL, SET_FILTER_BLOCKS } from "../actions/types";
const initialState = {
showTutorial: true, // <-- instead of initializying to true, do the axios call
filterBlocks: "ALL"
};
export default (state = initialState, action) => {
switch (action.type) {
case UNSET_TUTORIAL:
return { ...state, showTutorial: false };
case SET_FILTER_BLOCKS:
return { ...state, filterBlocks: action.payload };
default:
return state;
}
};
我不想使用 redux-persist,因为我想先了解正确的做法。
【问题讨论】:
标签: reactjs redux react-redux