Check out a free preview of the full Complete Intro to React v2 (feat. Router v4 and Redux) course:
The "Q&A: Using Compose & Why to Use Redux" Lesson is part of the full, Complete Intro to React v2 (feat. Router v4 and Redux) course featured in this preview video. Here's what you'd learn in this lesson:

Before moving on to the next topic, Brian spends a few minutes answering audience questions about why he’s using Compose. He also makes a few more arguments for the use of Redux in any application.

Get Unlimited Access Now

Transcript from the "Q&A: Using Compose & Why to Use Redux" Lesson

[00:00:00]
>> Speaker 2: Couple of questions going different way, why are we using compose?
>> Brian: This is kinda just the way that you apply this middleware. I don't know if I know exactly what compose itself does. Redux compose. This is the only reason I've used compose, just for the DevTools. Composes a function right to left.

[00:00:25]
>> Brian: You want to apply several store enhancers in a row. So it's just if you want to do multiple different store enhancers, which I'm guessing the DevTool is one store enhancer. It's also the only store enhancer I've ever used. So, that's what I got.
>> Speaker 2: And then how would we architect the filtering of the shows as a reducer?

[00:00:52]
>> Brian: So, I guess the way that you would do that is you would keep all of the shows inside of Redux. And then when you're doing your map state to props inside of there, you'll do the filter, so that you'd only be parsing the ones that you needed from, inside of that map state to prop.

[00:01:14] That's probably the way I would do it.
>> Speaker 2: There was a question for what resources would you recommend, I guess for making production quality code?
>> Brian: Specifically for React and Redux?
>> Brian: A lot of that comes down to build tools and how you're using your build tools. So, Kent C Dodds course on webpack would be a good place to start.

[00:01:45] There's another one coming out from Jim Young on how to deploy it and stuff like that, that would be a good place. Again, there's not too much specific to making React more production quality than it already is. The one key that you need to run a webpack in production mode and you have to send your node M to equal production, so that it builds React in production mode and not in dev mode and that's pretty much it for development verse production.

[00:02:17]
>> Speaker 2: And there's a request, Francois said, you mentioned you'd get to it, but he would really like to hear what the signs are that would make one use Redux.
>> Brian: I alluded to it a little bit earlier, but it's mostly that I have multiple components trying to read from the same data.

[00:02:38] Multiple unlike components, so I have all these TV shows that I need to read from and I have ten different components that are spread across my entire app, trying to read from these same shows. That's a big smell that I should like, okay, I need to centralize these shows in some way.

[00:02:56] Now there are some people that say, like go ahead and stick it on context. That's not the way I choose to do it. The way I choose to do it is to use something like Redux to distribute that across my entire app.
>> Brian: But yeah, it's when you need to centralize your source of truth and you're trying not to duplicate or keep things in sync, that's probably the best indicator.

[00:03:21] When you're trying to keep things in sync like you have two things that you're trying to keep synchronous, never do that. Just centralize your truth, roll it all together. Do something like Redux. We're gonna add one more thing to Redux before I move on. I've shown you how to do synchronous Redux and pretty much, I've shown you.

[00:03:43]
>> Speaker 2: Sorry question just popped in.
>> Brian: Sure.
>> Speaker 2: Craig is asking, can you use the form element properties from the method you call in the forms on submit?
>> Brian: The form element properties? Like are you trying to read the HTML attributes? Is that the question?
>> Speaker 2: I don't know for sure.

[00:04:06]
>> Speaker 3: You're probably serializing the inputs or something.
>> Speaker 2: Hang on let me ask that again, can you read the form input element properties from the method you call in the forms on submit?
>> Brian: I mean, there's many ways you can do that right. Like you can, it's a long answer to that question.

[00:04:30] The answer is I think what he's asking is- Like for instance, the hidden input or something, some some value in it and when you submit the form. And you're just keeping track of what's happening at the form level rather than each individual input possibly?
>> Speaker 2: Yeah.
>> Brian: The answer is you can absolutely do that, like it's just an HTML form.

[00:04:56]
>> Brian: For the most part, I would assert that, that's not what you wanna do. It's better to have React worry about each one of them individually. It's not always totally possible if you have like a dynamic form that you don't know what's gonna be in it, but I would say as much as possible, it's better to just be explicit about it.

[00:05:15]
>> Speaker 2: Okay.
>> Brian: Okay.
>> Speaker 2: Another question. Anton is asking, is that okay to use Redux without React router?
>> Brian: Is it okay to use Redux without React router? Yeah, I mean, our example, they're no way married to each other. So, you can use one without the other. They do not affect each other, unless you make them.