zustand
https://gyazo.com/0b9885319f847c27d71365283769228a
Reactでの利用を想定した軽量で高速な状態管理ライブラリ code:ts
import { create } from 'zustand'
type Store = {
count: number
inc: () => void
}
const useStore = create<Store>()((set) => ({
count: 1,
inc: () => set((state) => ({ count: state.count + 1 })),
}))
function Counter() {
const { count, inc } = useStore()
return (
<div>
<span>{count}</span>
<button onClick={inc}>one up</button>
</div>
)
}