Replies: 4 comments
-
|
Did you get this working? |
Beta Was this translation helpful? Give feedback.
-
|
Hi Kyle, I'm going back to the beginning to try to get an understanding. I tend to overthink which leads to overcomplicate and that's when i go round in circles. I was playing around and the $collectionId was live-query-1 and kept going up on every mount so know I'm wayy off the path. My thinking now is to create a query collection for each model in prisma as before. But now underneath that, const a Then i think back to the nested where it all started and thought do i need to create another seperate createLiveQueryCollection and go back to being confuzed. Not a package issue,, just a me issue on understanding. |
Beta Was this translation helpful? Give feedback.
-
|
Your runtime approach looks fine; the error you are hitting is just TypeScript telling you that the destructured prop in The important part is that So type the prop as a import type { Collection } from '@tanstack/react-db'
type LocationRow = {
id: string
region: string
country: string
buildingName: string
}
function LocationsList({
locationsCollection,
}: {
locationsCollection: Collection<LocationRow, string, {}>
}) {
const { data: locations } = useLiveQuery(locationsCollection)
return (
<ul>
{locations.map((loc) => (
<li key={loc.id}>{loc.region}</li>
))}
</ul>
)
}Why this works:
So this is not really a TanStack DB bug or a changed include pattern, just a missing prop type. The key mental model is: include/subquery field = |
Beta Was this translation helpful? Give feedback.
-
|
I've tried that before in looking for a resolution and it gave out more errors than just the any error. For the collection i get
Where adding the child LocationList, an error of missing fields etc shows up. That's when I go through the prisma, zod schemas to see what am I missing here. Is it typescript v6 whic i doubt, but that's the hole i go down and overthink. I've created a repo to clone as it could be the setup I'm using somehow.
Thanks for your time Dana |
Beta Was this translation helpful? Give feedback.
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