lpatipat
lpatipat

Reputation: 51

React Topic: Context vs Redux

What are the considerations I should be thinking of when it comes to choosing whether to use contexts to manage states in my front end vs using a state management system like Redux? Pros and cons?

Upvotes: 1

Views: 751

Answers (1)

Nick Carbone
Nick Carbone

Reputation: 218

For my latest app, once global state became overwhelmingly large and complex, I decided to use Redux and Redux Toolkit to separate concerns and:

  • pinpoint state variables in components with the useSelector hook
  • write mutating state logic in reducers (state.variable = something)
  • use awesome dev tools to 'rewind' state updates and trace actions to their source

I think use cases vary immensely. For instances where you just need to grab some value from up the tree, Context works great.

Read the docs on both and you will be better able to decide which is appropriate.

Upvotes: 2

Related Questions