i need help on type
Solution:Jump to solution
```typescript
export function StoreSetter<T extends keyof StoreType>({
store,
data,
}: {...
29 Replies
bro what
i want to add type to data prop in StoreSetter component
and what’s the issue?
should i send screen shot or copy paste the error
both is fine
ok i did this few min ago and
then this error is shown at top of setAtom(data)
Solution
with
StoreSetter({store: 'write2', data: [""]})
i have another request if you dont mind
sure go ahead
its ok, to set setAtom(...data) like that right, when I use useeffect it throws a hydration error because initially, it render empty form then get populated
btw not sure if you really want to pass the parameters as object
you could also do this:
and use it like this:
which i find to be nicer
so you want to use it as a component?
this is the whole picture, I have 5 tabs that are all client-side, and depending on the query(tab) URL I render them. but I want to fetch the initial data on the server side and pass the data to those tabs that contain multiple forms. so instead of drilling them via props, I created the store-setter component that receives data as a prop from the server side and sets the store. and the forms just get the initial data from the store.
okay i see then forget this ☝️
what do you think about this
and btw this shows error when i use writable atom, but works with normal atom
tbh i am not really sure - haven't used jotai with server components yet so your approach is new to me
I didn't use it on the server side, i just passed data from the server side to the client(via prop) and then set the atom on the client side
yeah normally you'd use a useEffect for setting an atoms value
does this help:
https://github.com/pmndrs/jotai/discussions/581
GitHub
Can an atom be initialised on the first render? · pmndrs jotai · Di...
I think I have a use case not sure if it's covered. I'm trying to replace a useState with useAtom but I can't provide an initial state with the atom except after the hook is initialised...
i think the provider approach is quite literally what you're building yourself rn
or this:
https://jotai.org/docs/utilities/ssr
Jotai
SSR — Jotai, primitive and flexible state management for React
Jotai takes a bottom-up approach to global React state management with an atomic model inspired by Recoil. One can build state by combining atoms and renders are optimized based on atom dependency. This solves the extra re-render issue of React context and eliminates the need for memoization.
Yes you are right, but when I tried it it doesn't work
Isn't this only supported only for next 12 and before that, next 13 broke it I think
yeah i think you're right
Maybe I should just use context with useReducer
And using useEffect ain't possible, tried it it keeps failing, and without it it works fine🤞
thank you for your help mate
sure!