Redux thunk + generators
You can use generators as action creators or thunks. Fully compartible with redux-thunk!
Installation
npm install --save redux-thunk-generators
Just replace redux-thunk import with redux-thunk-generators
Usage
You can use generators (sync or async) as thunks:
const signIn = { /* ... */ }
Or use generators as action creators:
const signIn = { /* ... */ }
Yield action objects to dispatch them! Forget about wrapping each time with dispatch
:
// Action creatorconst signIn = { const username password = payload; let state = ; // won't be dispatched, just returns current state ; try const response = await axios; ; ; return username; catch error ; ; };
yield
always returns a (new) state.
If you want to do something when your action is done, return
some data from generator and get it with .then:
;
Yep, nice) Tell your friend.
Author
@doasync