DEV Community

Brad Beggs
Brad Beggs

Posted on

Writing Thunks Workflow

Pre-req:
Install thunks

  1. Get organized - Create a thunks.js or a folder ./thunks/ and the appropriate file names to group the related thunks.

  2. Import action-creators from the appropriate file(s) into your thunk file.

  3. Write your thunk(s).

  4. Create a new reducer or update other reducers as appropriate and import any needed actions.
    4.1. If creating a new reducer, import it to store.js and add the reducer to your reducers object.

  5. In the component needing the thunk, import the thunk, add it to the appropriate props, mapState, and mapProps, and place the thunk function were needed in the component.

Resources & References

Redux-Thunk Official
What Are Thunks? <-the best article on Thunks and how they work

Top comments (0)