It seems that the correct way to type useLoaderData
has changed since V2.
export const loader = async () => {
return json({ messages: [...] })
}
// In component...
const { messages } = useLoaderData<typeof loader>
Prior examples show it typed differently, but now it is declared like this:
export declare function useLoaderData(): unknown;
This change seems critical, yet information about it is lacking. How can we ensure type safety in light of this new declaration? Is there a better method than using an ugly cast with as
?
Your insights are appreciated!