0
我有动作创建者的actions/index.js文件,而且我正在使用redux-thunk作为中间件。这是代码: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)?
我希望你能理解我的问题。如果不是,请添加评论,我会解释。
的同步流动'dispatch'是不确定的,但 –
'在这种情况下dispatch'将是不确定的,是的 – Remzes
对不起,你是对的我编辑我的帖子,你只需要返回一个对象,这是你的动作,如果你正在跟随一个同步流。 –