redux-thunk

Tags
frontend
Created
Nov 19, 2018 3:26 PM

https://stackoverflow.com/questions/35411423/how-to-dispatch-a-redux-action-with-a-timeout/35415559#35415559

作为 redux 的一个中间件,让 Redux 识别函数形式的 “actions”

这个函数(reduces)返回一个以 (dispatch, getState) 为参数的函数,在这个返回的函数中,可以进行多次 dispatch,或进行异步控制流;可以递归的调用该模式;

`this.props.dispatch(showNotificationWithTimeout('You just logged in.'))`

Redux 并不关心你从 thunk 返回什么,但是它会从 dispatch() 中获得它的返回值。 这就是为什么你可以从 thunk 返回一个 Promise 并等待它通过调用 `dispatch(someThunkReturningPromise()).then()` 来完成。

SuperMade with Super