🌟🌟🌟🌟:redux中间件 redux thunk
2019-03-26 本文已影响0人
达摩会武术
1:不使用中间件,store接收的action只能是对象;有了中间件,action可以是一个函数。
2:store接收一个action后,发现action不是对象而是函数,则会执行调用整个action函数。
3.使用了redux thunk后分别在todolist.js中和actioncreator.js中调用了dispatch,todolist中的dispatch是将函数派发到store然后自动执行,然后通过actioncreator里面的dispatch派发真正的action给store(个人理解)。
关于中间件:实际上就是对于dispatch方法的一个升级,不同的中间件对dispatch有不同的方法--ruedx thunk、redux logger 、redux-saga等等