I'd like to pass a default value to my nanostore state but the data comes from the server and I'm not sure how to stream it to client. I've had this problem in a few places now.
// store.ts
const visibleCategories = atom<string[]>([])
// I want to initially populate this arr with all categories
// and not be empty. But the categoreis come from server
---
// index.astro
const categories = await graphQLqueryResult()
---
<ReactComponent items={categories} client:load />
I don't like my current approach where I change the initial value inside useEffect. Code smell.
function ReactComponent({categories}){
useEffect(()=>{ visibleCategories.set(categories) },[])
return(
<div>
{
categories.map(c=>{
// Causes hydration errors and screen flash
if (!visibleCategories.includes(c)) return
return c
})
}
</div>
)
}
}
This (1) causes a flash where the list is blank and then comes alive and (2) Hydration problem