lstate
A simple, super-efficient and small (just 1.5kb) global state for React/Typescript applications
install
npm install --save lstate
usage
import React from 'react';
import { createGlobalState, useGlobalState } from "lstate";
const sample = createGlobalState({
initial: {count: 0},
reducers: (setter) => ({
inc() {
setter((old) => ({count: old.count + 1}))
},
})
})
export function App() {
const { count } = useGlobalState(sample)
return <div className="App">
<h1>Testing lstate</h1>
<h2>A simple, super-efficient and small (just 1.5kb) global state for React/Typescript applications</h2>
<p>count: {count}</p>
<button onClick={sample.inc}>+</button>
</div>
}
Click here to see a running demo