Why does routeData() return undefined?

I am fetching data from my Directus backend in createServerData$ like this:
export function routeData() {
return createServerData$(
async () => {
const directus = new Directus('http://localhost:8055')
return await directus.items('event').readByQuery()
}
);
}

export default function Home() {
const events = useRouteData()
createEffect(() => {
console.log(events())
})

//...
export function routeData() {
return createServerData$(
async () => {
const directus = new Directus('http://localhost:8055')
return await directus.items('event').readByQuery()
}
);
}

export default function Home() {
const events = useRouteData()
createEffect(() => {
console.log(events())
})

//...
However, the events variable is always undefined. I checked that the items are actually being fetched from Directus, and they are. And if I manually return a value from createServerData$ I can access it from the component. So what is going wrong here? Thanks!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server