Why useRouteData can return undefined?
In this example:
If I'm not an admin I'm redirected.
If no organisation is found with the
So I'm sure
Why?
export function routeData({ params }: RouteDataArgs) {
return createServerData$(
async ([_, id], { request }) => {
const user = await authenticator.isAuthenticated(request, {
failureRedirect: "/",
});
if (!user.isAdmin) {
throw redirect("/login");
}
return prisma.organisation.findUniqueOrThrow({
where: { id },
});
},
{ key: () => ["organisation", params.orgId] }
);
}
export default function AdminOrganisations() {
const organisation = useRouteData<typeof routeData>();
return (
<>
<Header>{organisation().name}</Header>
<Container>...</Container>
</>
);
}export function routeData({ params }: RouteDataArgs) {
return createServerData$(
async ([_, id], { request }) => {
const user = await authenticator.isAuthenticated(request, {
failureRedirect: "/",
});
if (!user.isAdmin) {
throw redirect("/login");
}
return prisma.organisation.findUniqueOrThrow({
where: { id },
});
},
{ key: () => ["organisation", params.orgId] }
);
}
export default function AdminOrganisations() {
const organisation = useRouteData<typeof routeData>();
return (
<>
<Header>{organisation().name}</Header>
<Container>...</Container>
</>
);
}If I'm not an admin I'm redirected.
If no organisation is found with the
idid, prisma throw.So I'm sure
const organisationconst organisation should be defined. But the type is stillconst organisation: Resource<Organisation | undefined>const organisation: Resource<Organisation | undefined>Why?