1 00:00:00,790 --> 00:00:04,990 We've now completed the process of putting together an action creator that's going to run some code 2 00:00:04,990 --> 00:00:11,020 to make an API request and then eventually dispatch an action with our data on the payload property. 3 00:00:11,030 --> 00:00:15,190 So now it's time to us to start focusing on our reducers to get started. 4 00:00:15,190 --> 00:00:21,010 We're going to flip on over to our code editor and find our reducers index such a file. 5 00:00:21,010 --> 00:00:25,510 You'll recall that inside of your we had that dummy reducer that we put in just to get our application 6 00:00:25,510 --> 00:00:26,410 working. 7 00:00:26,410 --> 00:00:31,300 So we're going to replace this thing in just a minute if you think back to last application that we 8 00:00:31,300 --> 00:00:36,730 worked on we had created all of our different reducers inside of the reducers index file. 9 00:00:36,790 --> 00:00:40,020 But this time around we're going to take a little different approach. 10 00:00:40,060 --> 00:00:44,830 Instead we're going to create a separate file for each reducer that we end up with. 11 00:00:44,830 --> 00:00:49,870 The idea here is that as we start to work on larger projects with many reducers putting them all inside 12 00:00:49,870 --> 00:00:52,710 of one file is probably not going to scale too well. 13 00:00:52,780 --> 00:00:58,480 So we're going to create a separate file for each producer in our reducers directory will then import 14 00:00:58,480 --> 00:01:03,680 them into this indexed file and wire them up to the combined reducers call. 15 00:01:04,170 --> 00:01:04,460 OK. 16 00:01:04,510 --> 00:01:09,130 So let's talk really briefly about the reducer that we're going to create right now. 17 00:01:09,310 --> 00:01:11,970 So we have an action creator to fetch our posts. 18 00:01:12,160 --> 00:01:17,880 That is going to dispatch an action with a type of fetch posts and our response on the Paller property. 19 00:01:18,160 --> 00:01:23,470 So we are going to create a post reducer and this thing is going to be responsible for watching for 20 00:01:23,470 --> 00:01:29,140 actions with type fetch posts and any time it sees that it's going to pull off that response right there 21 00:01:29,150 --> 00:01:32,400 in all the data inside of it and add it into some array. 22 00:01:32,440 --> 00:01:37,030 So we're going to eventually have a list of sorts with all of our different posts that have been fetched 23 00:01:37,030 --> 00:01:39,230 from our API OK. 24 00:01:39,230 --> 00:01:42,110 So let's flip back over and study my reducers directory. 25 00:01:42,130 --> 00:01:45,330 I want to make a new file called posts reducer. 26 00:01:45,380 --> 00:01:47,410 Yes. 27 00:01:47,510 --> 00:01:53,750 And then inside of here I'm going to put together an export default with an arrow function like so. 28 00:01:53,960 --> 00:01:59,930 And right now I'll just say return 1 to 3 so that or reduced or actually return some value and then 29 00:01:59,930 --> 00:02:03,120 I'm going to hook this up to my index file. 30 00:02:03,330 --> 00:02:13,520 So I'll flip back over at the top I will import those reducer from AU's reducer and then I'm going to 31 00:02:13,520 --> 00:02:16,730 assign that thing to our combined reducers call right here. 32 00:02:16,730 --> 00:02:25,960 So I will replace the replace me reducer with posts and that will be a post reducer like so. 33 00:02:25,990 --> 00:02:29,290 So now we're going to flip back over and start working on our reducer. 34 00:02:29,290 --> 00:02:33,310 Now we're not going to just straight up put the code for the reducer together. 35 00:02:33,310 --> 00:02:37,360 I want to take this as an opportunity to start talking to you then teach you a little bit more about 36 00:02:37,390 --> 00:02:43,390 exactly how reducers work and how we'd normally structured them inside of production style applications. 37 00:02:43,390 --> 00:02:44,850 So let's take a quick pause right here. 38 00:02:44,950 --> 00:02:48,700 When we come back the next section we're going to start to investigate these different rules and we'll 39 00:02:48,700 --> 00:02:51,570 start to eventually add some code to our posts or. 40 00:02:51,640 --> 00:02:53,950 So quick break and I'll see you in just a minute.