This course has been updated! We now recommend you take the State Management with Redux & MobX course.
Transcript from the "Redux tradeoffs vs React setState()" Lesson
>> Steve Kinney: And we wanna round back to that comment that I said in the Jetsetter application that we made an action for updating that new item input field. And it does raise a question of what goes in redux state versus what goes in react state. And there's a really great Medium article by Dan Amiroff, the creator of Redux, called You Might Not Need Redux.
[00:00:26] Right, and we've talked about this before, there are a lot of benefits from being able to kind of side load state into components without having to deal with the component hierarchy. But there are trade offs. And, depending on your application, that cost benefit analysis is different. And you don't necessarily need to use one approach everywhere, right?
[00:00:44] With different kinds of state you might want to different approaches and you can mix and match them, right? And so this is just bigger to make a point. So we ask ourselves the question of should we put stuff in the Redux store? And the answer, like most things, is that it depends.
[00:01:02] It's a trade off and what is a big trade off is indirection. If you think about the new item component, when we first created it, when we built Jetsetter, which basic state, everything that we needed was effectively in this component. I mean all it needed was what to do when the submit button was hit.
[00:01:20] Should we break it out into Redux? Well, we'll have the new item presentational component, then we'll wrap that map states [INAUDIBLE] dispatch the props, and that'll be in the new item container file. The actions will live in the new item actions, and the reducer for that will be in the items reducer, right?
[00:01:36] Or the new items text reducer, something along those lines, right? And so yes, we've broken it out. Now, we can side load the state and do effectively one component [LAUGH] right? So you have to make the choice if this is a good trade off for you, right? Cuz at the end of the day, while this.setState() does have limitations that we felt very early in this course, it also has some advantages, right?
[00:01:58] It is [LAUGH] effectively simpler to reason about and you get to mix and match these approaches based on the kind of state. When we think about state is there’s only one kind of state. We end up making poor choices. We’re better off thinking about what are the different kinds of state in my application and how do I want to manage those different kinds of state?
[00:02:16] You can manage them differently depending on what they are. So, again, in this case the new item input, we're doing it just to show and to kind of demonstrate, but I'd probably keep this in set state.