Home > Enterprise >  Context API , useReducer() or redux/rtk for state management
Context API , useReducer() or redux/rtk for state management

Time:04-20

I find the context api and useReducer a much nicer way of state management but some people are saying to use redux toolkit so can anyone explain what it is and how it is superior to the aforementioned context api and userReducer hook??

CodePudding user response:

React Context useReducer is a very simplified version of Redux.

They both can provide a clean action => reducer => update state flow that is held globally in your application. The key difference is Redux comes with a lot more tools that you would have to rewrite if you decided to go the route of Context useReducer.

The main thing being, popular middleware libraries! Redux has access to libraries such as redux-saga and redux-thunk that allow you to do asynchronous actions in a clean and manageable way.

Also you miss out on Redux Devtools, a very useful chrome extension for debugging state management in Chrome Devtools.

Basically, it's up to the application's complexity to decide which you use. I hope this helped a bit.

  • Related