Redux thunk分派不是一个函数
我有以下行动Redux thunk分派不是一个函数,redux,redux-thunk,Redux,Redux Thunk,我有以下行动 export function getAllBooks() { return function(dispatch) { return axios.get('http://localhost:8080/books') .then(response => dispatch(retrieveBooks(response.data))); }; } 问题是当我调用此操作时,我会进入控制台 未捕获(承诺中)类型错误:分派不是函数 评估时(评估时) 这是中的分
export function getAllBooks() {
return function(dispatch) {
return axios.get('http://localhost:8080/books')
.then(response => dispatch(retrieveBooks(response.data)));
};
}
问题是当我调用此操作时,我会进入控制台
未捕获(承诺中)类型错误:分派不是函数
评估时(评估时)
这是中的分派
。然后(response=>dispatch(retrieveBooks(response.data));
正在播放
除了redux thunk之外,我试过移除所有其他中间件,但都没有用
操作的唯一使用位置是
const mapDispatchToProps = (dispatch) => {
return { fetchBooks : () => dispatch(getAllBooks) };
}
您需要调用
getAllBooks
action creator并将内部函数传递给dispatch
const mapDispatchToProps = dispatch => {
return { fetchBooks: () => dispatch(getAllBooks()) } //note the dispatch call
}
您是否检查了
dispatch
实际上是什么?记录dispatch
对象,然后谢谢,我知道我已经接近了:(