DEV Community

Discussion on: Using React Central State to Simplify Your App

Collapse
 
juniusfree1 profile image
juniusfree

Hey. Newbie here.

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

Collapse
 
greenstage profile image
Eduardo Gomes

Hi,
-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.

Collapse
 
blnkspace profile image
AVI

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

Collapse
 
omrisama profile image
Omri Gabay

Thanks, came in here to ask this.