-
What's the idiomatic way to get returned data from useDebounceFetcher? My use-case is to display error messages that may be returned from the action. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
The response will have the data in |
Beta Was this translation helpful? Give feedback.
-
Sorry, my question was a bit a vague, I think it is more related to the typing, which is maybe where my confusion comes from. If I have an action like this: export const action = () => {
// ... whatever ...
return json({ firstName, lastName})
} Isn't this normal to type the fetcher? const fetcher = useFetcher<typeof action>();
const data = fetcher.data
const data: JsonifyObject<{
firstName: string;
lastName: string;
}> | undefined With debounceFetcher: const fetcher = useDebounceFetcher<typeof action>();
const data = fetcher.data This time const data: (({ request }: ActionFunctionArgs) => Promise<{
firstName: string;
lastName: string;
}>) | undefined Which is the type of the action function itself, not what it returns. So to use debounceFetcher with Typescript, I have to declare explicitly a new type rather than using typeof I suppose. This would work I think: const fetcher = useDebounceFetcher<Awaited<ReturnType<typeof action>>>() |
Beta Was this translation helpful? Give feedback.
The response will have the data in
fetcher.data
like auseFetcher
.