FAQ: Redux Middleware - Introduction to Thunks

This community-built FAQ covers the “Introduction to Thunks” exercise from the lesson “Redux Middleware”.

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

Learn Redux

FAQs on the exercise Introduction to Thunks

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!

Are the two code snippets the same? If not same can you explain to me?

1)

const remindMeTo = task => {

  return `Remember to ${task}!!!`

}

console.log(remindMeTo('call mom'))

const remindMeLater = task => {

  return () => {

    return remindMeTo(task);

  }

}

const reminder = remindMeLater('buy vegetable now');

console.log(reminder());

2)

const remindMeTo = task => {

  return `Remember to ${task}!!!`

}

console.log(remindMeTo('call mom'))

const remindMeLater = task => {

  return () => {

    return remindMeTo(task);

  }

}

const reminder = remindMeLater('buy vegetable now');

reminder();
1 Like

What exactly is happening when we use thunks?
I really don’t understand what I am suppose to learn in this exercise.

2 Likes

In the first one your logging reminder to the console and in the second, you’re not.

In the second one you are calling reminder but you are not logging what it returns to the console so you are doing nothing with the result of calling it (the “Remember to buy vegetable now !!!” string).

You’re basically just creating a function that doesn’t return the result immediately after calling it.

For example if we had the following :

reminder = remindMeTo(‘be cool’)

That means that in the variable reminder we now store a string (Remember to be cool !!!) since the return of remindMeTo(‘be cool’) gives us that string. And if we wanna see it we can console.log(reminder).

But if we have,

reminder = remindMeLater(‘be cool’)

The variable reminder now stores a function. Because remindMeLater(‘be cool’) returns a function, and only after we call it, that function returns the string. So if we wanna see the string, we have to call it inside the console.log(reminder());

its just a function that returns a function to be called at a later time.

you can also do const remindMeLater = task => () => remindMeTo(task);