From bd54069e6f822401be49aa8e6cdc875f144bb70f Mon Sep 17 00:00:00 2001 From: Michael Helvey Date: Wed, 19 Oct 2022 17:50:17 -0500 Subject: [PATCH 1/3] Support `typeof action` in useFetcher generic type. --- packages/remix-react/components.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/remix-react/components.tsx b/packages/remix-react/components.tsx index 0b084f5ae21..e14071cff28 100644 --- a/packages/remix-react/components.tsx +++ b/packages/remix-react/components.tsx @@ -1436,7 +1436,9 @@ export type FetcherWithComponents = Fetcher & { * * @see https://remix.run/api/remix#usefetcher */ -export function useFetcher(): FetcherWithComponents { +export function useFetcher(): FetcherWithComponents< + SerializeFrom +> { let { transitionManager } = useRemixEntryContext(); let [key] = React.useState(() => String(++fetcherId)); @@ -1446,7 +1448,7 @@ export function useFetcher(): FetcherWithComponents { }); let submit = useSubmitImpl(key); - let fetcher = transitionManager.getFetcher(key); + let fetcher = transitionManager.getFetcher>(key); let fetcherWithComponents = React.useMemo( () => ({ From 39e28bf5d77dda5268f2c21722b9497e3f42db3b Mon Sep 17 00:00:00 2001 From: Michael Helvey Date: Wed, 19 Oct 2022 17:55:34 -0500 Subject: [PATCH 2/3] add myself to the list of contributors --- contributors.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.yml b/contributors.yml index 3c5f7015ee3..5fd1def1b6d 100644 --- a/contributors.yml +++ b/contributors.yml @@ -294,6 +294,7 @@ - michaeldebetaz - michaeldeboey - michaelfriedman +- michaelhelvey - michaseel - mikeybinnswebdesign - mirzafaizan From 21c74e5920aea04ee5b078c007e3653ee720c0ca Mon Sep 17 00:00:00 2001 From: Pedro Cattori Date: Fri, 21 Oct 2022 14:32:19 -0500 Subject: [PATCH 3/3] Create witty-kiwis-flow.md --- .changeset/witty-kiwis-flow.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changeset/witty-kiwis-flow.md diff --git a/.changeset/witty-kiwis-flow.md b/.changeset/witty-kiwis-flow.md new file mode 100644 index 00000000000..d9a03216209 --- /dev/null +++ b/.changeset/witty-kiwis-flow.md @@ -0,0 +1,8 @@ +--- +"remix": patch +"@remix-run/react": patch +--- + +Infer the type of the `.data` property of `useFetcher` from `loader` and `action` functions. +Similarly to how you can write useLoaderData. e.g. you can now write useFetcher, and fetcher.data will be inferred correctly. +Previously, you had to write useFetcher>.