-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Here's the example code of zustand from link:
import { create } from 'zustand'
import { immer } from 'zustand/middleware/immer'
type State = {
count: number
}
type Actions = {
increment: (qty: number) => void
decrement: (qty: number) => void
}
export const useCountStore = create<State & Actions>()(
immer((set) => ({
count: 0,
increment: (qty: number) =>
set((state) => {
state.count += qty
}),
decrement: (qty: number) =>
set((state) => {
state.count -= qty
}),
})),
)Same logic and type safety in stalo:
import { create } from "stalo/lib/immer"
export const [useStore, setStore] = create({
count: 1,
})
export const increment = (n: number) => setStore((s) => { s.count += n })
export const decrement = (n: number) => setStore((s) => { s.count -= n })Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation