Check out a free preview of the full React Native (feat. Redux) course:
The "Redux Review" Lesson is part of the full, React Native (feat. Redux) course featured in this preview video. Here's what you'd learn in this lesson:

To conclude the first day with one more look at Redux. He walks through the existing code to reinforce the immutable nature of reducers and further explain the flow of data through the application.

Get Unlimited Access Now

Transcript from the "Redux Review" Lesson

[00:00:00]
>> [MUSIC]

[00:00:03]
>> Scott Moss: Any other questions on the stuff that we covered today? Yo.
>> Speaker 2: Would you mind kinda recapping like the Redux stuff, as far as like a higher level?
>> Scott Moss: Yep, yeah, I'll say that if anybody else doesn't have anything, I'll go over that. Anything else?
>> Scott Moss: No? Okay, all right, so higher-level Redux.

[00:00:26] So you gotta think about it like this. Let me, I'm gonna try to explain to you that kinda made sense to me. Cuz I gotta read things a couple times to kinda figure out what's going on. So the way I thought about it was, when I learned Redux it actually changed my life I was like wow I get it was that good to me it changed my life and you got think about it like this.

[00:00:46] So if you have state you're in your application right. You have all these components and you have state that you want to use in your application, application state not local state specific to the gov on it but state. Are you gonna use everywhere maybe like it lurks or notification stuff like that.

[00:01:02] And if you have them sitting inside on the component state then you can't really predict who's changing the state if it's new. If it's updated if it's still like you just don't know because it's all it's in many different places. What's the source of truth? So Redux is that source of truth is like hey just like you have a database on the server is like a let's put a single state store writing application.

[00:01:25] So Redux wasn't the first thing to do that's just a flux thing. The thing about Redux that actually took them off and like made a better was like if we like flux we like dispatching actions, we like single state store, but we're gonna do that we're going to take this mythology of like reducing things so what they do is the whole point is to have your state in one place and that way when you stay in the one place you can do things like transformations time travel logging you can apply all these middleware to your state because it's in one place exactly where your state is.

[00:01:57] And there's only one way to access it and that's through action. There's no other way to access that you can't come in here and say you know Redux.state.Todos+1 you can't do that. There's no way to do it. The only way to access the state is a fire going to action.

[00:02:11] So now and then you create those actions yourselves. Right. And then with a reducer or does it taste action and is like okay given this action. This is the new state. Is what the new state's gonna like. So there's no way that you can have like unpredictable side effects because all the producers are pure functions.

[00:02:28] They don't do third party calls they don't call the server they only return state they're pure no side effects. So that means your state is exactly gonna be the way you describe it to be nothing more nothing less. So now is really predictable. So now you've never really great tooling and now you know what's actually happening because you can only change the state with an action.

[00:02:48] You're not like worried about like wow this is crazy but going on the why this thing equals two you have to worry about that you never call the X in the first place and there's no way that that state. Unless the action was called somewhere else. It's really easy to figure out what's actually happening in the application.

[00:03:03] You call a action. You change or you create a new state. And then the app updates. That's it. You don't modify the state ever. It's always immutable. If you go look at the reducers here. The reason we do this like why do we just say state push action dot payload and just return that.

[00:03:19] As we would be modifying the state. So, what we do is we create a entirely new array with the payload in it plus the old stuff it. So, it's immutable, right. That way we don't have to like we're not mutating state which is actually That's when stuff gets really confusing we start mutating stuff like okay, I don't actually know what's going on here anymore.

[00:03:38] We're just like you create a new state every single time, always. So yeah, that's high level, pretty much it. But basically for me it's just like one place where the state is that we can do crazy things like you'll see tomorrow we'll do thonks. On the Web you have like logging you'll have all types of other stuff.

[00:04:00] And then just describing like what happens when that stage changes. So what happens when somebody adds a post. This happens. And that's it. This is the only place that is going to change the state. Nowhere else in this application is the state ever going to get changed other than right here.

[00:04:15] So now we don't have to think about where this actually happened or what actually happened. We can just look at the actions. Go back in time until we figure out when this actually happened and if you can see what the transformation was and that's it. Any other questions on this?

[00:04:41]
>> Scott Moss: Yeah it's. All right so do we have any more questions for today? I want to do is go over briefly we're going tomorrow. So we're going to be doing tomorrow is so amazing designs for the app.
>> Scott Moss: Is look out of here. So about.
>> Scott Moss: So here's this sweat book app.

[00:05:06] Some pretty pretty okay out. To be like in our design this. So it's great. It's literally just it's a fitness logging app so you can go to the you can go to the gym. You can as exercises and use as your sets is gonna be using some A-P-I is like a secret storage so storing things locally on a device but still getting the asynchronous.

[00:05:32] Lessons from fetching and it's going to use in different opponents like we're going to use type aheads, we're going to use linear gradient agency, we're going to have a sliding tab navigation, we're going to have nav bars and all types of stuff. So we'll be covering a lot of that stuff tomorrow.

[00:05:49] And it's, this will actually be like a production ready app that you can, like, use on your phone or put somewhere and it'll work, like a pretty solid one. And then there'll also be lessons for, like, future stuff that we just didn't have time to build or that you can add yourself too if you want.

[00:06:04] So this is what we'll be doing tomorrow.