Skip to content
Advertisement

Tag: redux-thunk

Unit testing react redux thunk dispatches with jest and react testing library for “v: 16.13.1”,

I have following function. const loadUsers= () => { return async (dispatch) => { dispatch(userRequest()); let response= null try { response= await UserService.getUser(); dispatch(userLoading()); } catch (error) { dispatch(userError(error)); } finally { dispatch(userSuccess(response)); } }; }; With the following unit test I was abale to hit the “dispatch(userRequest());” describe(‘user thunk’, () => { it(‘dispatches a userRequest’, async () => {

Cannot call Action within another Action

I am having trouble understanding this behaviour I have an action defined like this and whatever() is defined like this I expect whatever() to be executed, but it is not. Why is that? Answer Both onDone and whatever here are not “actions”, they are “action creators”. They are functions that return an action (“thunk actions” in this case). An action

Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/await

There is a lot of talk about the latest kid in redux town right now, redux-saga/redux-saga. It uses generator functions for listening to/dispatching actions. Before I wrap my head around it, I would like to know the pros/cons of using redux-saga instead of the approach below where I’m using redux-thunk with async/await. A component might look like this, dispatch actions

Advertisement