DEV Community

Discussion on: Why React projects still use Redux

Collapse
 
wicked7000 profile image
Wicked • Edited

I think it comes down to size of the application I've mentioned this on another thread/post before. Your post even touches on it to some extent but if you need a highly testable code base using state/Context can make it much harder. This is because you have to essentially test the component and the state at the same time. With redux you can do these two things mostly independently (you could argue that you still need tests on how your component reacts to certain state updates and so forth).

I also feel like redux 'handles' global state in a much more maintable way for larger applications. However this is pretty much entirely a preference I don't think it's impossible to use Context API/state I think you might just have to be a bit more delligent with how you design your application.

Prior to my most recent project I was using a mix of the Context API and normal react state. However I ran into the problems of testing that I mentioned above. However that's just my two cents I'd be curious to see how others feel!

TL;DR: I feel there is a place for both it depends on the size and testing requirements of a project

Collapse
 
alexandrudanpop profile image
Alexandru-Dan Pop

Nicely said. With Redux we can have independent tests for 3 parts:

  • the components
  • the reducer
  • the sagas
Collapse
 
wicked7000 profile image
Wicked

Yeah my structure is usually that of:

  • Basic action creator functions (non-thunk)
  • Thunks
  • Reducer
  • Component

I haven't actually got around to trying react-saga and am just using react thunk. But I should get around to trying that out too