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>
15 lines
423 B
TypeScript
15 lines
423 B
TypeScript
'use client'
|
|
|
|
import { useEffect } from 'react'
|
|
import { useProductStore } from '@/stores/product-store'
|
|
|
|
export function SetCurrentProduct({ id, name }: { id: string; name: string }) {
|
|
const { setCurrentProduct, clearCurrentProduct } = useProductStore()
|
|
|
|
useEffect(() => {
|
|
setCurrentProduct(id, name)
|
|
return () => clearCurrentProduct()
|
|
}, [id, name, setCurrentProduct, clearCurrentProduct])
|
|
|
|
return null
|
|
}
|