Context API vs Redux in React Native Apps

Home / Blog / React Native / Context API vs Redux in React Native Apps

2/15/2021

Context API vs Redux in React Native Apps

Quick start - why Context API?

After many projects of mobile applications in React Native, in which I used Redux to manage the state of the application, I decided to try something else, i.e. Context API in this case.

My next project was quite good for that because it wasn't sharing a large amount of data between components, and the application itself did not have a very complicated structure - just in time to try another technology.

First try

The first impressions were very good. Far less state management code. Zero installing additional packages. No duplicating boilerplate copying. The use of the Context API also encouraged me by the low entry threshold compared to the first meeting with Redux. Someone who has used Redux more than once for sure asks himself "Are you sure that's all?" while using Context API for the first time.

Ease of use is undoubtedly the biggest advantage of the context API over Redux. However, there are a few topics that you should keep in mind when deciding to replace Redux with the built-in React tool.

There are drawbacks

In my opinion, the biggest problem especially in larger applications, where often we update the data inside the application may be the fact that updating the context value the component consumer re-renders.

It seems that this is not a problem, because in the end, for example, to display the updated data, we have to re-render the component. However, in this case, the re-rendering of the components will apply all context-related components.

This can cause problems in performance (especially if you don't know about it 😅).

Summary

In some cases, using the context API can also make us a bit confusing creating reusable components, especially if the data comes from context and not from props.

However, looking at what the context API offers us as a whole, it's great alternative to Redux, especially in "small" projects, or projects in which we have a lot of static data, or the data update is minimal. Certainly more than once you were wondering when installing Redux into an application consisting of 2-3 views or Redux is not simply an "overkill".

Of course, the context API isn't a golden mean, but you should consider using it in your projects.

Author

Adrian Janakowski

React Native Developer

?

Not sure what tech to choose?

Reach out to aur executive consultants for personalized guidance on how best to approach your project