Rollin
Rollin

Reputation: 354

Redux vs Context API + React Hooks - which wins in performance?

Im curious which of mentioned tools could be better solution for better app performance. Which of them causes less re-renders?

Looks like ContextAPI causes re-render of whole component tree if any of context state changes.

Also what about Context API + React hooks? (useReducer).

I feel that redux would perform a lot better, maybe anyone has specific numbers who is winner in this category?

Upvotes: 3

Views: 3499

Answers (2)

Arman
Arman

Reputation: 801

If your application is large and has complex state management, then redux is a better choice as it'll make your application handier to manage states, Separate logic from UI, better code organization, easy debugging etc.

But if your application is a small or medium level application, go for Context API. As it requires minimal Setup and ships perfectly with React.

Upvotes: 3

Md Joynul Abedin
Md Joynul Abedin

Reputation: 250

The popular opinion Redux is for large projects & Context API for small ones.

Both are excellent tools for their own specific niche, Redux is overkill just to pass data from parent to child & Context API truly shines in this case. When you have a lot of dynamic data Redux got your back!

The Context API could be used in place of Redux if you are just using it to prevent passing props down to deeply nested components, as it is designed specifically for this use case.

But there is no reason for you to stop using Redux if you already do ( centralizing your application's state, handling logic outside of components,predictable state container, using Redux DevTools to track when, where, why, and how your application's state changed, using plugins like Redux Form, Redux Saga, Redux Undo, Redux Persist, Redux Logger, etc.). None of these are accessible using the Context API.

Upvotes: 6

Related Questions