Check out a free preview of the full Intermediate React, v2 course:
The "Creating Actions" Lesson is part of the full, Intermediate React, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Brian demonstrates how to create an action that takes a reducer and returns an action.

Get Unlimited Access Now

Transcript from the "Creating Actions" Lesson

[00:00:00]
>> Brian Holt: Now inside of your directory, inside of source we're gonna make a new folder. And that one's gonna be called actionCreators. This isn't necessarily a requirement, but I find this to be helpful and I would say many people do it. Sometimes people will just directly create the actions, but we're gonna make action creators.

[00:00:23] So we're going to make this one, this one's gonna be called ChangeLocation.js. And this is just going to export a function called export default function.
>> Brian Holt: changeLocation, that takes in a location, and it returns an object of type: CHANGE_LOCATION, and payload is going to be location.
>> Brian Holt: This is what an action looks like, right?

[00:01:06] So this is an action creator, right? It's a function that you give it a location it gives you back an action.
>> Brian Holt: And again, people will just sometimes directly dispatch objects that look like this. I'm fine with that as well. But I'm just gonna teach you kind of the more structured way to do it, and then I'll leave it up to you how you wanna do it,

[00:01:27]
>> Brian Holt: Okay?
>> Brian Holt: We're gonna make one more here, and this is going to be called changetheme.js. Looks relatively the same, changeTheme(theme), theme and CHANGE_THEME,
>> Brian Holt: Okay?