Join Richard Gill for an in-depth discussion in this video What is Redux and why do we care about it?, part of Performing Complex State Management with Redux.
a way of storing application's state, and I guess the first thing you really need to understand with Redux is, like, What is it? Why might you want to use it? So, the problem Redux is trying to solve is when you build larger applications, generally, so maybe something a little bit bigger than just like a toy example, and generally, when people have built that size of application, it gets a little bit bigger, they start to notice bugs creeping in quite consistently, some of those bugs can be quite hard to fix. And this, a lot of the motivation for Redux, and really what's called the "Flux design pattern," which is what Redux is one implementation of, was born out of Facebook with a bug that they had with the chat window in the old Facebook site before it became its own thing.
And so, the bug they had was the, a little one "unread" notification would pop up, the user would read the message, and then the one would come back again. And they realized that this bug was, like, really hard to track down. They fixed it, and then it kept coming back and they had really smart engineers wasting loads of time. And so some clever person somewhere sat down and they were like, "What is it we're doing wrong? "Why is this so hard for us to fix?" And what they came up with is something called the "Flux design pattern." So it's a design pattern, it's a way of structuring code, it's a set of rules for how you should write programs and just structuring them in a specific way to, like, make things easier for you.
And then your application becomes a set of transformations between those states. So maybe you've got, you know, a page with three Reddit posts on and someone enters a new Reddit post, well then, what should happen is you should, the Redux state will have the three Reddit posts and then when you reload the page the fourth one appears and you'll have the fourth one in Redux state. And then your application just becomes about managing the state, transitioning the state from one thing to another, and then binding that state to the UI you are building.
Now this all sounds pretty generic when I talk about this, but what we're gonna show you through these sequence of videos some practical kind of examples of how you can use Redux, what it is. And Redux is about third popular framework to implement the Flux design pattern. Before that, there was "Flux," and then "Reflux," and then, I think, "Redux." There were lots of others along the way. There's also another similar technology called "MobX" which has gained some momentum, but Redux is by far still the most popular. I don't think it matters which library you use that much and I think they all have quite similar ideas.
I've been using Redux for a couple of years now and I really like it. It's a little bit difficult to understand at first and it can be a little bit cumbersome. You have to create quite a lot of files, and that's definitely a downside of that. But overall, it makes things super simple and what I really like about the Flux design pattern in Redux is I know exactly where each bits of my code should go and I know what the rules are. There's very clear rules in Redux and there's not a lot of ambiguity and there's a program where I love that, because it means when I'm working with my colleagues, it's easy to make decisions because there are nice clear rules and you can just say, "Well, you know, the rule is this is how it works, "and you haven't done it like that," or "I haven't done it like that, so I'm wrong," and it makes things easier.
There are some ambiguities to Redux which we'll talk about maybe nearer the end, but I think, overall, things are pretty clear. Yeah, it's a really good library, I really recommend it if you work with, it works really well with React, but the concept, and Redux actually works with other libraries, so you can use it with Angular, you can use it with Vue.js, or you can use it with many things. The concept is the main thing that's important, rather than the specific library. I'm using the specific library just to show you because it's easier to see things when you see them working. And it works super well with React, that's what it was kind of designed for, but it is a separate library, and you can use it with other things.
Note: This course was created by Packt Publishing.
- What is Redux?
- Connecting your components to the store
- Firing actions
- Applying Redux reducer
- Using advanced reducers
- Dispatching asynchronous actions with Thunk
- Building a workable application