@@ -3,10 +3,15 @@ import { Alertbox, Content } from '@obosbbl/grunnmuren-react';
33import { createFileRoute , notFound } from '@tanstack/react-router' ;
44import type * as props from 'component-props' ;
55import { defineQuery } from 'groq' ;
6+ import type { COMPONENT_QUERYResult } from 'sanity.types' ;
67import { sanityFetch } from '@/lib/sanity' ;
78import { AnchorHeading } from '@/ui/anchor-heading' ;
89import { PropsTable } from '@/ui/props-table' ;
9- import { ResourceLink , ResourceLinks } from '@/ui/resource-links' ;
10+ import {
11+ ResourceLink ,
12+ type ResourceLinkProps ,
13+ ResourceLinks ,
14+ } from '@/ui/resource-links' ;
1015import { SanityContent } from '@/ui/sanity-content' ;
1116import { ScrollToTop } from '@/ui/scroll-to-top' ;
1217import { TableOfContentsNav } from '@/ui/table-of-contents-nav' ;
@@ -29,22 +34,22 @@ const COMPONENT_QUERY = defineQuery(
2934
3035export const Route = createFileRoute ( '/_docs/komponenter/$slug' ) ( {
3136 component : Page ,
32- loader : async ( { params } ) => {
37+ loader : async ( { params } ) : Promise < { data : COMPONENT_QUERYResult } > => {
3338 const res = await sanityFetch ( {
3439 query : COMPONENT_QUERY ,
3540 params : { slug : params . slug } ,
3641 } ) ;
3742
38- if ( res . data == null ) {
43+ if ( res . data === null ) {
3944 throw notFound ( ) ;
4045 }
4146
42- return { data : res . data } ;
47+ return res ;
4348 } ,
4449} ) ;
4550
4651function Page ( ) {
47- const { data } = Route . useLoaderData ( ) ;
52+ const { data } = Route . useLoaderData ( ) || { } ;
4853
4954 const _ghLink = data . resourceLinks ?. find (
5055 ( link ) => link . linkType === 'github' ,
@@ -61,7 +66,12 @@ function Page() {
6166 { data . resourceLinks ?. map (
6267 ( { url, linkType = 'other' , text, _key } ) =>
6368 url && (
64- < ResourceLink key = { _key } type = { linkType } href = { url } text = { text } />
69+ < ResourceLink
70+ key = { _key }
71+ type = { linkType as ResourceLinkProps [ 'type' ] }
72+ href = { url }
73+ text = { text }
74+ />
6575 ) ,
6676 ) }
6777 </ ResourceLinks >
0 commit comments