In the last section we created our action creators file inside the actions directory.
So now we're going to start creating our first action creator right back over here.
Remember we had said that we probably want to have an action creator called something like select song.
So back over here I'm going to say Konst select song that's going to be the name of my action creator.
I'm going to make it an arrow function and then remember this needs to return a plain javascript object
just as a quick reminder I'll put some comments on here for myself.
I'll remind myself that this is my action creator and inside of it we are going to return an action.
Now remember the rules of javascript are me redux actions we must have a type property and we can optionally
have a payload as well.
When we were going over that example inside of Copen I'd said several times that we have to have a payload.
We don't actually have to have a payload property on any action.
It is technically optional but a type is required.
So I'm going to add in type of song selected like the now in this case we are going to have a payload
because we want to specify exactly what song we are trying to select.
So I'm going to assume that we're going to pass in the song that we're trying to select as an argument
to the actual creator.
And so all reflect that as an argument called Song and then all assign that to my payload like so and
that's it that's all we need for our single action creator.
It's not the last thing we do is make sure that we export this action creator from this file up to this
point in this course.
We've been exporting everything using the export default statement so we've been writing out stuff like
export default select song like so but you're going to very quickly see that as we start to write multiple
action creators inside this file we might want to export multiple different functions.
So rather than creating a default export we're going to instead create a named export a named export
allows us to export many different functions from a single file to do so.
All we have to do is place the export keyword right in front of that function declaration.
All right so now we can save this.
Now I want to very quickly give you an example of how we would import this select song action creator
into another file.
So again going back over to my apt J.S. file at the top to import that I would write out.
Import curly braces and then select song like so and then I would say from dot dot slash so up one directory
the actions folder to the curly braces right here.
Specifically mean that we want to import a named export from this file.
If we had a export default in here instead like export defaults select song then we would not need those
curly braces and we would take them off like so.
Now one thing that I've found is that when you're first getting started with import and export statements
it's incredibly common to just kind of like guess whether you need the curly braces or not.
So I encourage you don't guess don't just randomly put on curly braces and if you have a bunch of other
import statements inside of your don't just do what you had done on the others.
Instead think about what you are trying to import here.
Is it a named export or a default.
If it is a default no need for the curly braces.
If it's names you need the curly braces.
All right.
So I'm going to remove that import statement because in this case we don't need it and then I'm going
to save my index such as file here.
After removing that export at the bottom.
OK so that's it.
That's our final file for the actions index dodgiest file those take a quick pause here.
When we come back the next section we're going to start working on our reducers as well.
So I'll see you in just a minute.