react/redux don';返回调度
我真的不知道为什么这个动作不起作用。操作在返回调度功能之前停止(仅记录“工作”) 但几乎相同的行动是没有问题的。我错过了什么明显的东西吗react/redux don';返回调度,redux,react-redux,Redux,React Redux,我真的不知道为什么这个动作不起作用。操作在返回调度功能之前停止(仅记录“工作”) 但几乎相同的行动是没有问题的。我错过了什么明显的东西吗 export function getPosts(page){ return function(dispatch){ dispatch({ type: IS_FETCHING }); axios.get(`${URL}/home?page=${page}`) .then(response =>
export function getPosts(page){
return function(dispatch){
dispatch({ type: IS_FETCHING });
axios.get(`${URL}/home?page=${page}`)
.then(response => {
dispatch ({
type: FETCH_POSTS,
payload: response.data
})
})
.catch((error) => {
dispatch({ type: ERROR_FETCHING });
});
}
}
为子孙后代:
这通常发生在您单独调用thunk函数时,这意味着内部函数不会传递给dispatch()
:
您如何称呼每个动作创建者?我猜
getPosts()
被正确调度,而authAdmin()
实际上没有被调度(只是单独执行)。是的,就是这样:)谢谢:)
export function getPosts(page){
return function(dispatch){
dispatch({ type: IS_FETCHING });
axios.get(`${URL}/home?page=${page}`)
.then(response => {
dispatch ({
type: FETCH_POSTS,
payload: response.data
})
})
.catch((error) => {
dispatch({ type: ERROR_FETCHING });
});
}
}
import {someThunkActionCreator} from "./actions";
// Wrong - just returns the inner function, but never runs it
someThunkActionCreator();
// Right - passes the inner function to dispatch, which runs it
dispatch(someThunkActionCreator())
// Right - creates a bound-up version which auto-dispatches
const boundThunk = bindActionCreators(someThunkActionCreator, dispatch);
boundThunk();