solid start routeData errors

reposting here cause got no help in solid server yet
5 Replies
nexxel
nexxelOP3y ago
hi, im quite new to solid and solid start so this might be a dumb question. im fetching data from my database in the routeData function using createServerData$. im not sure if i have gotten it right though because when i reload my page, it has a flash of undefined and then changes into the classic [object Object]
nexxel
nexxelOP3y ago
import { Match } from "solid-js";
import { type RouteDataArgs, useRouteData } from "solid-start";
import { createServerData$ } from "solid-start/server";
import { prisma } from "~/server/db";

export const routeData = ({ params }: RouteDataArgs) => {
return {
page: createServerData$(
async (name) => {
return await prisma.page.findUnique({
where: { name },
select: { name: true },
});
},
{ key: () => params.name }
),
};
};

export default function Page() {
const { page } = useRouteData<typeof routeData>();

return (
<>
<Match when={!page()}>
<h1>Not Found</h1>
</Match>
<Match when={page()}>
<h1>{page()?.name}</h1>
</Match>
</>
);
}
import { Match } from "solid-js";
import { type RouteDataArgs, useRouteData } from "solid-start";
import { createServerData$ } from "solid-start/server";
import { prisma } from "~/server/db";

export const routeData = ({ params }: RouteDataArgs) => {
return {
page: createServerData$(
async (name) => {
return await prisma.page.findUnique({
where: { name },
select: { name: true },
});
},
{ key: () => params.name }
),
};
};

export default function Page() {
const { page } = useRouteData<typeof routeData>();

return (
<>
<Match when={!page()}>
<h1>Not Found</h1>
</Match>
<Match when={page()}>
<h1>{page()?.name}</h1>
</Match>
</>
);
}
nexxel
nexxelOP3y ago
on logging data data fetched from prisma i can see its sometimes null and sometimes its defined https://this-vegetable.is-from.space/Alacritty-v0.10.0-portable_(1)_gQOKGTLgy0.png
nexxel
nexxelOP3y ago
what is wrong here? bump lol solved
Want results from more Discord servers?
Add your server