DEV Community

Using React Central State to Simplify Your App

Eduardo Gomes on January 06, 2019

React-central-state is an easy-to-use React library created to help you share a common state between your components without passing state to props...
Collapse
 
revskill10 profile image
Truong Hoang Dung

The critical difference is: With Redux, i don't need React to describe my application state, React is just the view layer, i could go with vanilla JS or jQuery with Redux.

So this solution is too framework-coupling, so it's not good, or unusable to me.

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
 
omrisama profile image
Omri Gabay

Thanks, came in here to ask this.

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
 
zoltanradics profile image
Zholtan Choo

I was using Redux so far amd it always worked, but I find this solution interesting. Sometimes reducers and action creators are too much hassle. I will give this a try at least for a smaller project

Collapse
 
jorge_rockr profile image
Jorge Ramón

Nice, it's an easier approach than redux