Blogify

Blogify

redux

Why I Use RTK Query for API Calls in React

Volodymyr

Volodymyr

Post

What is Redux

A lot of people think of Redux as a state management library, which it is. To them, the main value of Redux is that it makes it possible to access (and change) the application state from anywhere in the application. To me, this misses the point of using something like Redux, so let’s zoom out a bit and take another look.

We’ve all seen this diagram, or something like it:

Animation of action being dispatched from the UI with a payload that updates the store, which in turn updates the UI with the new state.

Source: Redux Fundamentals tutorial.

You can see that, in this model, the UI has a place to display the current amount from the store, and buttons that the user can click to indicate she wants to deposit or withdraw money. As soon as one of those buttons is clicked, we move outside of the component to dispatch the action based on what the user has requested. Note that at this point, the state has not changed. Next, the action arrives at the store, and the reducer looks at it to decide what, if anything, to do about the user’s request. If the reducer decides to honor the user's request, that…