From the course: Building Modern Projects with React

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Creating a thunk

Creating a thunk

From the course: Building Modern Projects with React

Start my 1-month free trial

Creating a thunk

- [Narrator] Now it's time to create our first thunk. Inside our to-do folder, let's create a new file called thunks.js and this is where we'll put the thunks for our project. So what does a thunk actually look like? Well, in Redux, a thunk is simply a function that returns another function, which contains the actual logic that we want to perform when it's triggered. So for our first thunk, let's do something fairly simple. We're going to define a thunk called display alert. So we'll say export const displayAlert, and what it's going to do is simply return another function that displays an alert on the user's screen. So we'll say alert, hello. So this is about as simple as thunks can get. We'll see later on how we can add a lot more functionality to our thunks, but first let's see how to dispatch a thunk. You might be happy to find out that the way we dispatch a thunk is nearly identical to the way that we dispatch…

Contents