-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于在一个异步action中无法调用另一个异步action的问题(同步action可以) #12
Comments
上面触发另一个action的方式,是这样的 topicActions.testTecchingTopic(); //同步action, 测试通过
topicActions.fetchingTopic(); // 异步action, 没有响应
如果使用dispatch dispatch(topicActions.testTecchingTopic()); //同步
dispatch(topicActions.fetchingTopic(json)); //异步
|
需要dispatch的,看起来没什么问题。。。 const store = createStore(
reducer,
applyMiddleware(thunk)
); 应该: // 调用 applyMiddleware,使用 middleware 增强 createStore:
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore)
const store = createStoreWithMiddleware(reducer) http://redux.org.cn/docs/api/createStore.html |
@Jeepeng 感谢解答,还是有几个问题
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers/index';
// Note: this API requires redux@>=3.1.0
const store = createStore(
rootReducer,
applyMiddleware(thunk)
);
最后还是感谢解答 |
确实,redux@>=3.1.0可以这样用createStore, |
@Jeepeng 感谢解答,我再研究研究 |
我也遇到了同样的问题,请问怎么解决的? |
@WoolYang 这个是很久之前的问题了,我其实也忘了怎么解决的,估计我也没解决这个问题,现在我也不再使用redux, 而是使用另一个数据管理的库mobx, 强行安利,很好用,具体可以看我的这两个分享:
希望能对你有帮助 |
也遇到过此问题,不过我的dispatch代码如下(成功执行):
官方给出的示例代码为:
尽管少了一层return 函数,但是确实能够获取到dispatch/getState,代码能够执行;redux-thunk的源码为:
将函数createThunkMiddleware改变一下,不难发现,我们通过dispatch传入的其实就是action,
如果我的理解有偏差,欢迎交流探讨~~ |
@RocketV2 感谢回复,但是这个问题已经是很久之前的问题了,而且现在我已经很久很久没有使用redux了,现在用的mobx, 很好用 |
背景是这样的:
starAction.js
topicActions.js
The text was updated successfully, but these errors were encountered: