-
Notifications
You must be signed in to change notification settings - Fork 71
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(即引入redux的react项目如何使用异步ajax) #6
Comments
参考资料:阮一峰:Redux 入门教程(二):中间件与异步操作
这里解释了中间件的添加位置,因为是在发送action的这个阶段,在这个阶段去处理异步请求,然后在ajax的回调中再dispatch对应的action |
在action文件中做出变化,本来在actions文件中定义了一些action creator, 用来生成一个action对象返回,然后dispatch这个对象到store中,现在这个action creator不返回一个对象而是返回一个函数,这个函数中是ajax的代码和其回调函数,这意味着原来dispatch一个对象,现在为了处理异步dispatch了一个函数,为了使得dispatch能够发送一个函数,需要用到redux-thunk这个库对dispatch方法做一个改造,使得dispatch可以接受函数作为参数. 参考资料:阮一峰:Redux 入门教程(二):中间件与异步操作
参考资料: 我们为什么要用 redux-thunk
|
问题
The text was updated successfully, but these errors were encountered: