Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReturnType useDebounceFetcher #289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

caprolactam
Copy link

@caprolactam caprolactam commented Dec 11, 2023

fetcher.data should infer the response data from your action or loader. However, in the current implementation, fetcher.data infer the type of your action or loader itself.

Modify type to allow useDebounceFetcher to infer the return value correctly.
I am referencing the following source code in Remix.
https://github.com/remix-run/remix/blob/bc0b77569655a163f3c5ebc87ad034a5fc297e2b/packages/remix-react/components.tsx#L1038-L1042

Example
before
before fix
after
after fix

If the use of @remix-run/server-runtime is undesirable, I'm considering modifying the code as follows. What do you think?:

type DebouncedFetcher<Data = unknown> = Omit<
	ReturnType<typeof useFetcher<Data>>,
	"submit"
> & { submit: DebounceSubmitFunction };

@stephen776
Copy link

I am running into this issue now as well trying to migrate to single-fetch. Any ideas @sergiodxa?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants