TanStackT
TanStack6mo ago
6 replies
brilliant-lime

notFound data always nested in data.data, and props.data type is unknown

Hello)

In defaultNotFoundComponent, props.data is typed as unknown. At runtime, props.data is an object: { data: T, isNotFound: true, routeId: string }.

The user-provided data T from return notFound({ data: T }) is unexpectedly nested under props.data.data

repo: https://stackblitz.com/edit/tanstack-router-zzqpfdfg?file=src%2Fmain.tsx
// need select post by id

//posts.$postId.tsx
  loader: ({ context: { queryClient }, params: { postId } }) => {
    return notFound({
      data: 'Hello data',
    });


// main.ts
defaultNotFoundComponent={(props) => {
          return (
            <div>
              Error:
              {JSON.stringify(props.data, null, 2)}
            </div>
          );
        }}
Was this page helpful?