There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
I can’t seem to figure this our i checked my answer to the solution and it was identical but it does not allow to me continue, it says “The thunk returned by loadRecipes should dispatch an action with payload equal to the recipes returned by fetchRecipes() .” Someone please help!
To get the user with id = 32 , we can call dispatch(getUser(32)) . Note that the argument to dispatch is not an object, but an asynchronous function that will first fetch the user’s data and then dispatch a synchronous action once the user’s information has been retrieved.
I’m confused by this. Hoping someone can help me understand. If the function getUser returns a function itself with 32 as the argument then how does this work? I thought dispatch took an action object? How does this work?
I may have just found my own answer in the next part of the lesson:
redux-thunk Source Code
At this point, you are ready to use thunks to define asynchronous operations in Redux. But you may be curious about how redux-thunk works. In order to allow us to write action creators that return thunks in addition to plain objects, the redux-thunk middleware performs a simple check to the argument passed to dispatch . If dispatch receives a function, the middleware invokes it; if it receives a plain object, then it passes that action along to reducers to trigger state updates.
If you look into App.js, you will see that loadRecipes is beign imported as a named import.
Likewise, useDispatch is beign imported there as well, so loadRecipes can make use of it.
My guess is that ‘useDispatch’ in allRecipesSlice.js is missing the named export statement export, which, I think, is where the confusion comes from. As it is now in the code, the app won’t work since App.js won’t be able to find loadRecipes in allRecipesSlice.js.