Sub-layout sets product in Zustand store; NavBar reads it. getAccessibleProduct wrapped with React cache to avoid double DB call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
13 lines
432 B
TypeScript
13 lines
432 B
TypeScript
import { create } from 'zustand'
|
|
|
|
interface ProductStore {
|
|
currentProduct: { id: string; name: string } | null
|
|
setCurrentProduct: (id: string, name: string) => void
|
|
clearCurrentProduct: () => void
|
|
}
|
|
|
|
export const useProductStore = create<ProductStore>((set) => ({
|
|
currentProduct: null,
|
|
setCurrentProduct: (id, name) => set({ currentProduct: { id, name } }),
|
|
clearCurrentProduct: () => set({ currentProduct: null }),
|
|
}))
|