Neuron Global State Manager

Neuron

Global State Manager

Count: 0


 <p>Count: <span id="count">0</span></p>
 <button id="incrementBtn" onclick="increment()">Increment</button>

 <script>
   window.onload = (event) => {
     const Neuron = NeuronCore.Neuron;
     const counter = new Neuron(0);

     function increment() {
        counter.set((prev) => prev + 1)
     }

     const counterNode = document.querySelector("#count");

     counter.effect((payload) => {
       counterNode.innerHTML = payload.state;
     });
   };
 </script>

import {neuron} from '@sandstack/neuron/react'

const useCount = neuron(0);

function Comp(){
  const [count, countActions] = useCount()

  return(
    <>
     <p>Count: {count}</p>
     <button onClick={() => countActions.set((prev) => prev + 1)}>
      Add
     </button>
    </>
  )
}