And one more interesting Riddick's concept that I would want to show you is how we can create action
creators.
Now, it sounds way more complicated than it really is.
And the general idea behind action creators is following where notice when we're setting up our functions.
Correct.
We have this dispatch and then, of course, we do need to have our actions object and then we need
to pass in time.
And it is fine in our small application because, of course, we're just despatching, for example,
the removal action one time.
But then you can imagine as your application grows and you need to rewrite this multiple times in some
way, you're asking for trouble because you might introduce the bug.
And the way action creators work is we set up the function that always, always returns our particular
type.
And then optionally if we want to pass some kind of parameters in function, of course we can do that.
Now, I will not refactor all my actions again.
That would be an oracle.
However, we will rewrite our remove action using the action creator just so you can see the benefit
of that.
And like I said, it would be a function.
So instead of passing it manually, our actions object with the type.
We're just going to set up a function that does that for us.
I'm going to go with export again.
We would need to export it since we'll use it instead of a plan of action.
And then, as I always call it, whatever you want, I'm going to go remove item.
And then, like I said, it will be a function.
Let me set this up as a empty function.
And then, like I already previously mentioned, the whole point of this action, creator, is to always
return a proper action with a proper type.
So in our case, since I'm setting up action creator for removal, of course I will return the action
object with a type of remove.
So I'm going to return.
Then I'm returning my object type.
Yes, you guessed it will be removed.
And then remember for remove, we still needed the payload.
So that doesn't change.
I still need to pass here the payload.
In my case, I'm going to send this up as an object and then I'm passing in the area.
And now probably the question is, well, where are we going to get this?
Well, we're setting this up as a function.
Correct.
So I'm just going to say, alright, so just pass here as an argument.
My idea now I will say my actions and then of course we will navigate to Karakoram because that's where
we're using the remove item.
Now we do need to import it.
So I have increased decrease and all that.
So now I'm just going to be importing my remove item.
OK, awesome.
And then let's scroll down to the bottom and then replace our simple remove where we manually wrote
or type removing all that payload and pass in at this patch our function again, it sounds way more
complicated than it really is.
What you're doing is you're taking out the manual labor of setting up your action objects by hand just
by passing here, removing them.
Now we're still getting our ID from our own props so I can pass in Mayadeen right here.
And as you will see, the functionality will not change.
But just imagine the scenario where you would have an application where you would need to dispatch your
remote location 20 times.
So which option would be easier and potentially have less bugs?
You have a function where you just need to pass the area and you always, always will have your type
correct equal to remove.
And yes, you would send them up in the same file.
Might as well.
You have your actions so you right away can pass it or the other option would be manually again type
increase, then payload and all that.
And I think we have a pretty clear winner because I think it is much more easier to get our function
and then optionally pass some kind of argument, if you would have to.
If you don't have to, then you would always just return the correct action type.
So that's how we can set up our action creators.
Now, let me double check, because that would be hilarious if I'm trying to show you a better way how
you can set up your application to avoid bugs.
But then I would introduce bugs in my own application one to three and let it go on so we can set up
the actual creators in our redox application.