mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-05 04:05:14 -05:00
* feat(claude): added rules * fix(copilot): chat loading; refactor(copilot): components, utils, hooks * fix(copilot): options selection strikethrough * fix(copilot): options render inside thinking * fix(copilot): checkpoints, user-input; improvement(code): colors * fix(copilot): scrolling, tool-call truncation, thinking ui * fix(copilot): tool call spacing and shimmer/actions on previous messages * improvement(copilot): queue * addressed comments
1.7 KiB
1.7 KiB
paths
| paths | ||
|---|---|---|
|
Zustand Store Patterns
Stores live in stores/. Complex stores split into store.ts + types.ts.
Basic Store
import { create } from 'zustand'
import { devtools } from 'zustand/middleware'
import type { FeatureState } from '@/stores/feature/types'
const initialState = { items: [] as Item[], activeId: null as string | null }
export const useFeatureStore = create<FeatureState>()(
devtools(
(set, get) => ({
...initialState,
setItems: (items) => set({ items }),
addItem: (item) => set((state) => ({ items: [...state.items, item] })),
reset: () => set(initialState),
}),
{ name: 'feature-store' }
)
)
Persisted Store
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
export const useFeatureStore = create<FeatureState>()(
persist(
(set) => ({
width: 300,
setWidth: (width) => set({ width }),
_hasHydrated: false,
setHasHydrated: (v) => set({ _hasHydrated: v }),
}),
{
name: 'feature-state',
partialize: (state) => ({ width: state.width }),
onRehydrateStorage: () => (state) => state?.setHasHydrated(true),
}
)
)
Rules
- Use
devtoolsmiddleware (named stores) - Use
persistonly when data should survive reload partializeto persist only necessary state_hasHydratedpattern for persisted stores needing hydration tracking- Immutable updates only
set((state) => ...)when depending on previous state- Provide
reset()action
Outside React
const items = useFeatureStore.getState().items
useFeatureStore.setState({ items: newItems })