Use react context as a global state provider
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
public
src
.gitignore
LICENSE
README.md
package.json
yarn.lock

README.md

React context as a global state manager

Why

Just for the lulz

What

This is the code that will be explained in a medium article in my blog

TL;DR

  • AppContext.js declares a context provider and a context consumer, the context provider also has a state and a function to update the state

  • connect.js provides a simple api for forgetting about the internal of the context and just connect a component to the global state

  • Cat and Dog are consumer to the state, index.js is the "connect" and Cat/Dog.js are stateless component

  • ChangeFamily shows how to change the global state