DEV Community

Discussion on: Using React Central State to Simplify Your App

juniusfree profile image

Hey. Newbie here.

What's the difference of this library from React Context API? TIA

greenstage profile image
Eduardo Gomes Author

-The Context API lets you create a relationship between one data provider and multiple data consumers.

-Central State kicks the state out of all react components and lets them read and change its properties.

-With Context, either you create a new container for each shared property, or you wrap all properties on the context object. -> But then be ready for a lot useless re-rendering.

-Central State dispatched updates on subscribed properties changing, not the whole state, and also gives you control over them on shouldcomponentupdate().

-With only React Context, if you need to change a state property inside a consumer component, you'll have to define a new function embedded in the context itself.
This may have the advantage of isolating concerns like mutating the state -making it easier to debug- but it also gives you lot of extra work.

Well that's my view on it, at least.
But I like this library mostly because of its simplicity.

blnkspace profile image
Aviral Kulshreshtha

that answer demystified it for me! thanks! I'm surely gonna try this out in smaller projects, that don't need redux & redux-saga or Apollo, etc

omrisama profile image
Omri Gabay

Thanks, came in here to ask this.