1 00:00:00,160 --> 00:00:07,210 Just to recap every time we used a user juicer we needed to pass in to values reduce our function and 2 00:00:07,230 --> 00:00:14,670 then initial state and then what we're getting back is the state and then the function that controls 3 00:00:14,670 --> 00:00:14,780 it. 4 00:00:15,130 --> 00:00:21,060 And in this case that is going to be a dispatch function and then we'll just call the dispatch function 5 00:00:21,360 --> 00:00:26,430 with whatever action we would want and we set up actions as variables. 6 00:00:26,430 --> 00:00:31,830 Because that way it was easier to avoid the mistakes where we just have a typo. 7 00:00:31,840 --> 00:00:38,790 Now I also don't want to cover well why we didn't use everything within the same state because we technically 8 00:00:38,790 --> 00:00:44,610 could have we could have had the reducer that is looking for everything that is looking for total as 9 00:00:44,610 --> 00:00:45,840 well as car homes. 10 00:00:45,970 --> 00:00:49,550 Then also keep in mind that your juicer is not going to be anymore. 11 00:00:49,620 --> 00:00:51,300 A simple array. 12 00:00:51,300 --> 00:00:55,210 It's not going to be an empty array that we're getting back from the local storage. 13 00:00:55,260 --> 00:01:00,480 It's in fact going to be a giant object and then you're just adding a bit more complicated functionality 14 00:01:00,780 --> 00:01:05,810 where you still need to return to host state because remember that was one of the keys when you working 15 00:01:05,820 --> 00:01:10,050 with producer you must and I'm going to repeat this 70000 times. 16 00:01:10,050 --> 00:01:15,300 You must must must must must you must return a new state. 17 00:01:15,300 --> 00:01:16,850 You cannot just mutate the state. 18 00:01:17,010 --> 00:01:19,690 And if you're making your state more complicated. 19 00:01:19,770 --> 00:01:23,240 Well of course if I'm adding more values in here it's not anymore. 20 00:01:23,250 --> 00:01:24,350 A simple array. 21 00:01:24,420 --> 00:01:26,880 In fact it's going to be an object with the properties. 22 00:01:26,880 --> 00:01:31,920 Then you also need to make sure that each and every time you're going to update something within a state 23 00:01:32,250 --> 00:01:34,140 that you're returning that state. 24 00:01:34,140 --> 00:01:39,630 So in that case of course you would use something like this where you're going to go with return return. 25 00:01:39,750 --> 00:01:41,560 Dot dot dot state. 26 00:01:41,580 --> 00:01:45,570 And like I mentioned before we're going to do this a lot when we're working. 27 00:01:45,570 --> 00:01:47,740 Actually we did in the redux section. 28 00:01:47,820 --> 00:01:53,820 So that's the reason why I just went with the simple array and in this case I can just return here every 29 00:01:53,820 --> 00:02:01,110 time I use some kind of method that returns a new array since I can use state then filter this returns 30 00:02:01,110 --> 00:02:04,160 new Array anyway and then I just look for that item. 31 00:02:04,230 --> 00:02:07,890 That's the reason why I didn't add everything within my state. 32 00:02:08,190 --> 00:02:14,310 And the way reducer works is we use the dispatch function then we say whatever type of action we would 33 00:02:14,310 --> 00:02:18,350 want to perform and then optionally we can pass in the payload. 34 00:02:18,480 --> 00:02:24,080 And as you can see the real benefits of user juicer is as your project gets bigger. 35 00:02:24,220 --> 00:02:28,490 Or let's say you're getting more team members because there's more structure to it. 36 00:02:28,560 --> 00:02:34,080 People kind of just come in here and start updating state willy nilly they're going to have to dispatch 37 00:02:34,080 --> 00:02:38,940 their actions and then with the reducer they're going to have to make sure that they're returning new 38 00:02:38,940 --> 00:02:39,500 state. 39 00:02:39,620 --> 00:02:44,860 And that way they're going to have some guardrails instead of somebody comes in and then just mutates 40 00:02:44,860 --> 00:02:48,800 the state and everyone else's functionality has been messed up.