FAQ: Managing Promise Lifecycle Actions - createAsyncThunk()

This community-built FAQ covers the “createAsyncThunk()” exercise from the lesson “Managing Promise Lifecycle Actions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Redux

FAQs on the exercise createAsyncThunk()

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 (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 (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 (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Why just can’t explain arg and thunkAPI in this exercise?

const loadRecipes = createAsyncThunk(
  'allRecipes/loadRecipes',
  async (arg, thunkAPI) => {
    const response = await fetchRecipes(arg); <-- Problem here
    const data = await response.json();
    return data;
  }
)

It makes me wonder why I can’t put arg inside fetchRecipes().
As in the exercise example showed:

import { createAsyncThunk } from '@reduxjs/toolkit'
import { fetchUser } from './api'
const fetchUserById = createAsyncThunk(
  'users/fetchUserById', // action type
  async (arg, thunkAPI) => { // payload creator
    const response = await fetchUser(arg);
    return response.json();
  }
)
3 Likes

Can’t explain arg becouse fetchRecipes don’t used args, fetchRecipes give allRecipes.

Iam honestly confused, when middleware in redux were introduced , they had to be passed into the configurestore function using applyMiddlewar but now that we are using redux thunks, which are also a type of middleware, why arent we passing this middle ware to the “applymiddleware” in configureStore. what am i missing?

1 Like

To be honest, I grow irritated starting from the React router section to Redux section. A LOT OF STUFF WERE NOT EXPLAINED CLEARLY, freaking confusing to learners. Learners have to spend a lot of unnecessary time figuring out somewhere else what the heck what it is teaching. A little bit layman term would help instead of long articles with fancy terms that confuse the heck out of learners.

Let’s go back to problems in this part:
1 . at least explain a bit about the naming of type.
2. could have just explained arg thunkAPI alltogether in this part.
3. my answer should have been accepted since I only make my own variable names:
const recipes = await fetchRecipes()
const result = await recipes.json()
return result
but no, I had to go copy solution to pass, and still not knowing why I must return json version.

1 Like

First they told us that middleware is supposed to intercept thunk, yet after their teaching, I still find no relation between their logger middleware and the recipe thunk presented to us.
Now to your question, the answer is: no, they did not elaborate AT ALL. My search shows that applymiddleware is when you use createStore from ‘redux’. but when it comes to configureStore from ‘@reduxjs/toolkit’, you dont need it. but if you really want to use the logger middleware they taught us under configureStore, you would have to do something like as follows:

import { configureStore, getDefaultMiddleware } from ‘@ reduxjs/toolkit’;

const store = configureStore({
reducer: rootReducer,
middleware: [logger, …getDefaultMiddleware()],
});

Not sure if it is correct, all I want to complain is the lack of simple explanation for learners but instead bunch of long-A fancy term paragraphs