From the course: Building Modern Projects with React

Why do you need Redux Thunk?

From the course: Building Modern Projects with React

Start my 1-month free trial

Why do you need Redux Thunk?

- [Instructor] Previously, we saw how adding Redux to our React application furthered our goal of separation of concerns by giving us a centralized controlled way of managing state through actions and reducers. And basically what this means is that our components no longer have to worry about controlling their own states and this is great, since it means that the business logic for what sort of state transformations are allowed to take place and how they take place is no longer contained inside of our component files. And this simplifies our components conceptually, as well as in terms of the number of lines of code they contain. However, even with Redux in place our components still have to contain the logic for doing all the asynchronous operation, such as fetching or updating server data. We call these sorts of operations side effects. Now conceptually, we want our components to have only one concern, correctly displaying the data we give them. So these side effects should be moved out of our components, if possible, and of course, it is possible by using what are referred to as side-effect libraries in our applications. There are several side-effect libraries that are available to React developers. Two of the most popular ones are Redux Thunk and Redux Saga. Now, despite the somewhat cryptic names, the goal of these side-effect libraries is more or less the same, to give us a way to separate the side effects of our application from our components. So, in terms of relative popularity, that is in terms of GitHub stars at least, Redux Saga is in a pretty big lead. However, because of the relative simplicity and smaller learning curve of Redux Thunk, we're going to be covering Redux Thunk in this course. But just understand that, if at some point in the future you want to look into Redux Saga or some other side-effect library instead, they're all used to solve roughly the same set of problems as Redux Thunk.

Contents