【发布时间】:2018-03-20 23:20:37
【问题描述】:
我有带有动作创建者的动作/index.js 文件,并且我使用 redux-thunk 作为中间件。这是代码:
export const fetchUser = () => async dispatch => {
const res = await axios.get('/api/current_user');
dispatch({type: FETCH_USER, payload: res.data});
};
export const handleToken = (token) => async dispatch => {
const res = await axios.post('/api/stripe/', token);
dispatch({type: FETCH_USER, payload: res.data});
};
export const submitSurvey = (values, history) => async dispatch => {
const res = await axios.post('/api/Surveys', values);
history.push('/Surveys');
dispatch({type: FETCH_USER, payload: res.data});
};
export const scrollMovement = (scrollValue) => dispatch => {
dispatch({type: SCROLL_MOVE, payload: scrollValue})
};
export const selectConfig = (id) => dispatch => {
dispatch({type: "SELECT_CONFIG", payload: id})
};
我有一个问题。我是否应该以与我编写 hadleToken、submitSurvey 和 fetchUser 动作创建者相同的风格编写不向外部 API(例如,scrollMovement 和 selectConfig)发送请求的动作创建者?
希望您能理解我的问题。如果没有,添加cmets,我会解释。
【问题讨论】:
标签: reactjs ecmascript-6 redux redux-thunk