lstate
A simple, super-efficient and small (just 1.2kb) 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: 1},
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, efficient and small (just 2kb) global state for React applications</h2>
<p>count: {count}</p>
<button onClick={state.inc}>+</button>
</div>
}