S
SolidJS14mo ago
gh680

Can't get createServerData$ to work as expected

I have other projects that use routeData / createServerData$ / useRouteData that work fine. This one is giving me fits. In the below, trying to read the records() accessor gives me "records is not a function"
import { For } from 'solid-js'
import { createServerData$ } from 'solid-start/server'
import { useRouteData } from 'solid-start'
import prisma from '~/db/prisma'

export function routeData() {
return createServerData$(async () => {
const data = await prisma.company.findMany({})
return data
})
}

export default function TableView() {
const records = useRouteData<typeof routeData>()

return (
<div>
<For each={records()}>{rec => <p>{rec.name}</p>}</For>
</div>
)
}
import { For } from 'solid-js'
import { createServerData$ } from 'solid-start/server'
import { useRouteData } from 'solid-start'
import prisma from '~/db/prisma'

export function routeData() {
return createServerData$(async () => {
const data = await prisma.company.findMany({})
return data
})
}

export default function TableView() {
const records = useRouteData<typeof routeData>()

return (
<div>
<For each={records()}>{rec => <p>{rec.name}</p>}</For>
</div>
)
}
My prisma schema/client are cool, typings there are good. I've reduced the code to a minimal example and it still doesn't work. I've tried everything I know, and still no joy. Ideas anyone? Thanks
7 Replies
Braveheart
Braveheart14mo ago
async await that fn in createServerData$
gh680
gh68014mo ago
Edited code above to include async/await. Did not change the outcome unfortunately.
Braveheart
Braveheart14mo ago
can you debug and put breakpoint at const data = await prisma.company.findMany({})
gh680
gh68014mo ago
@Nikos thanks for the replies. I think my problem was that my route component was re-exporting the above from another location in the project. It seems that solid-start requires that my routeData/createServerData$ code physically live in the route component itself (?). If I bring that code into the route component itself, then things work.
navi.ToTskie
navi.ToTskie14mo ago
hi. i found the solution
Braveheart
Braveheart14mo ago
cool
gh680
gh68014mo ago
@totskie730 thank you, this works great. I was over-invested in trying to make a specific approach (using useRouteData example from the docs) and didn't know how to refactor for my specific case. Appreciate your taking the time to post a working solution.