When to use React Redux and Context API?

How can i decide when to use Context API or Redux with react project. ?
In what types of projects React Redux is used and Context API, and what are the main deciding factors ?

Both are great for when you need to share data that can be considered “global” for a tree of features, such as the current authenticated user, theme, or preferred language.

The Context API is great for relatively simple apps where there is a few pages at most as it was originally made for higher read operations than write operations. When some data needs to be accessible by many components at different nesting levels, or when global themes are needed. Apply it sparingly because it makes component reuse more difficult. It causes reloading of the pages, where as redux won’t do that.

Redux is ideal for more complex apps, or if you’re planning on scaling. Its powerful global state management ability to handle data coming from multiple endpoints allows you to influence a single component/view.

There is also Composition, which is great for the most simple apps, particularly when you want to avoid passing some props through many levels.

There seems to be a bit of performance discrepancy between Redux and Context if your app scales as well, so keep that in mind.

This is a helpful reference for more clarity: When to use Redux and when to stick to Context API?

1 Like

The react context has been there for a while. It is much better now with the coming of React hooks. It has so many benefits, including the fact that no third-party libraries are needed by the context API. We can use it in React apps to manage our state like redux.

Context is mainly used when many components at different nesting levels need to be able to access some data. Apply it sparingly because it makes component reuse more difficult. Component composition is often a simpler solution than context if you only want to avoid passing some props through many levels.

I had come across an article for this: https://medium.com/@loginradius/what-is-react-context-api-and-how-to-use-it-best-a64b73eb722e?postPublishedType=initial

It might be useful for you too. Pls see :slight_smile: