0.0.0-alpha.1 • Published 4 months ago

@sandstack/neuron-react v0.0.0-alpha.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

npm version build npm bundle size

Neuron React

The Neuron Global State Manager is a small, bare bones, framework agnostic library for building framework specific global state managers.

Neuron Vanilla can be used in any js application by itself or you can tailor it to your framework of choice. My goal is to create framework specific version of this that use vanilla under the hood. See Neuron React as an example.

Setup Store

Create a new Store

import Neuron from "@sandstack/neuron";

export const Store = Neuron.Store();

Add initial state to Store

Store.add({
  key: "name",
  state: "Ash Ketchum",
});

Store.add({
  key: "age",
  state: 10,
});

Update state

Store.set("name", "Gary Oak"); //key, new state

Get state

Store.get("name"); //key

Listen for state changes

Store.onDispatch((dispatchItem) => {
  if (dispatchItem.key === "name") {
    console.log(dispatchItem.state);
  }
});

//initial console.log output
//name: Ash Ketchum

//new console.log output
//name: Gary Oak

You can learn more about Neuron here.