In the last video we had a discussion around how we're going to fetch data inside of a redux app.
So now that we have a better idea of what's going on let's flip back over to our code editor and we're
going to start putting all this stuff together.
All right so going to first begin by creating a new folder inside my sarcy directory called actions
and inside of that directory I'm going to make a new file called index Scace us.
So eventually inside of here we're going to put our action creators.
Right now let's just put together kind of like a stub of an action creator just to kind of have something
that we could import back over to our posts list and make sure that we call it any time that our component
is mounted on the screen or gets rendered to the screen.
So inside if you're going to say export Konst that posts
right now I'll just return a action with a type of something like batch posts like so that'll do for
right now.
Now let's make sure that we can wire this up to our component and call it any time that our component
is rendered on the screen.
So going to change back over to my post list component to wire our action creator up to this thing we
have to import the connect function from reactor redux.
And we also have to import that fetch posts action creator that we just made and excuse me the import
path right here is going to be dot dot slash actions like the Senao done you're an export default.
We can put together our connect function.
Now remember we do not have a map state to prop's function right now.
We will eventually but at present there is no state or no data that we want to get into this component.
Nonetheless we still have to pass in a first argument to the connect function.
The first argument is always going to be Mount St. to prop's But in this case because we do not have
a map state to prop's function I'm going to just pass in no to indicate that we don't have any state
that we want to get into this component.
So now I can pass in my action Creator as the second argument.
So I'll say Fetch posts is fetch posts and remember we can use a little bit of yes 20:15 syntax to shorten
this up to just fetch posts like so.
All right so now inside of our component we can define the component.
Did mt life cycle method Saray above render all say component.
Did mount an inside there.
I will call this stop Propst start fetch posts.
Ok so now the instant our component is rendered on the screen we should be calling our action creator
so our action creator fecche post will be called at present it's going to return in action with type
fecche posts and that's pretty much it for right now.
Now if we felt like over we can test this out just very quickly and just make sure we don't have any
error messages or anything like that.
OK so looks like we're just fine here.
Now take another quick pause.
When we come back the next section we're going to wire up our request over to that J some placeholder
API inside of our action creator.
So quick pause and I'll see you in just a minute.