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 () => {
Tag: redux-thunk
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
How to make React Redux async action return a promise?
I have a redux action function that returns a promise. Inside that function body, there is another async function that returns a callback when it finished the call. Then I call this function in another place chaining it with .then() but when debugging it in the browser with breakpoints, the promise function exists after the first two lines of code
react redux useSelector rerender even when data does not change
I am using react with redux and redux thunk. I have an action where I am making a network request. With the useSelector I am getting the data from redux store. I have a problem that the component rerenders every time when I dispatch the action. I want that the component only rerenders when data changes. I tried already use
Dispatch() calls a function but .then() doesn’t work on React-Redux
I’m creating my first React-Redux App. I’m using yo generator-redux and following this repo and official documenation. I have rendered de SignIn Presentational Component and it works fine, show errors if inputs are blanks. The problem is at dispatching. I use Thunk Middleware but the repo doesn’t. I have used console.log() to explore how deeper is working my code and
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