You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
95% of my app is based on a tree view, like gitHub I guess. Previously using react query i had a nested prisma call and could build the tree nodes from that data. Messy but it worked. Doing optimistic mutations on those nodes, i tried but was a hell no.
Reading what it says on the tin, ts-db seems the perfect fit for this. My previous attempt I never subscribed the children for the reactive updates. When i go back to the component it would refetch the children every time as I guess they had no parent.
//query.tsximport{eq,useLiveQuery}from"@tanstack/react-db";import{accountsCollection}from"#/collections/accountsCollection";import{locationsCollection}from"#/collections/locationsCollection";exportfunctionAccountList(){const{data: accounts}=useLiveQuery((q)=>q.from({a: accountsCollection}).select(({ a })=>({id: a.id,name: a.name,locations: q.from({l: locationsCollection}).where(({ l })=>eq(l.accountId,a.id)).select(({ l })=>({id: l.id,region: l.region,country: l.country,buildingName: l.buildingName,})),})),);return(<ul>{accounts.map((act)=>(<likey={act.id}>{act.name}{/* Pass the child collection to a subcomponent */}<LocationsListlocationsCollection={act.locations}/></li>))}</ul>);}functionLocationsList({ locationsCollection }){// Subscribe to the child collection for reactive updatesconst{data: locations}=useLiveQuery(locationsCollection);return(<ul>{locations.map((loc)=>(<likey={loc.id}>{loc.region}</li>))}</ul>);}
Everything is fine until the prop for the LocationsList. I get an error of
Binding element 'locationsCollection' implicitly has an 'any' type.
I thought no problem. No matter what i tried to resolve, it did not work. Just threw more errors into the function above. Got AI involved and still no resolution. THis is most likley user error, but has something changed to how this works now?
Granted it's extreme for these 2 be in collections as they will hardly, if ever be mutated. But just trying to get an understanding of how it works to progress more. Any help would be appreciated.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
95% of my app is based on a tree view, like gitHub I guess. Previously using react query i had a nested prisma call and could build the tree nodes from that data. Messy but it worked. Doing optimistic mutations on those nodes, i tried but was a hell no.
Reading what it says on the tin, ts-db seems the perfect fit for this. My previous attempt I never subscribed the children for the reactive updates. When i go back to the component it would refetch the children every time as I guess they had no parent.
So I've tried to follow this example with my code below.
https://tanstack.com/db/latest/docs/guides/live-queries#using-includes-with-react
Everything is fine until the prop for the LocationsList. I get an error of
Binding element 'locationsCollection' implicitly has an 'any' type.I thought no problem. No matter what i tried to resolve, it did not work. Just threw more errors into the function above. Got AI involved and still no resolution. THis is most likley user error, but has something changed to how this works now?
Granted it's extreme for these 2 be in collections as they will hardly, if ever be mutated. But just trying to get an understanding of how it works to progress more. Any help would be appreciated.
Respect and thank you.
Beta Was this translation helpful? Give feedback.
All reactions