From 3d60844f1b37e96a132d3908450c74c0df1ca08c Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Tue, 21 Jan 2025 15:27:13 +0100 Subject: [PATCH] Fixed issue with typescript --- package.json | 2 +- src/hook/index.tsx | 10 +++++++--- src/utilities/index.test.ts | 6 +++--- test-apps/react-router/app/routes/home.tsx | 9 +++++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index e87f355..9bf44a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "remix-hook-form", - "version": "6.1.2", + "version": "6.1.3", "description": "Utility wrapper around react-hook-form for use with react-router v7+", "type": "module", "main": "./dist/index.cjs", diff --git a/src/hook/index.tsx b/src/hook/index.tsx index aba6ace..2f48997 100644 --- a/src/hook/index.tsx +++ b/src/hook/index.tsx @@ -28,9 +28,9 @@ import { type FormMethod, type SubmitFunction, useActionData, + useHref, useNavigation, useSubmit, - useHref, } from "react-router"; import { createFormData } from "../utilities"; @@ -225,7 +225,7 @@ export const useRemixForm = ({ onInvalidHandler, )(e); }, - [methods.handleSubmit, submitHandlers, onSubmit, onInvalid], + [methods.handleSubmit, submitHandlers, onSubmit, onInvalid, basename], ); const hookReturn = useMemo( @@ -242,7 +242,11 @@ export const useRemixForm = ({ return hookReturn; }; -export type UseRemixFormReturn = ReturnType; +export type UseRemixFormReturn = UseFormReturn & { + handleSubmit: ReturnType["handleSubmit"]; + reset: ReturnType["reset"]; + register: ReturnType["register"]; +}; interface RemixFormProviderProps extends Omit, "handleSubmit" | "reset"> { diff --git a/src/utilities/index.test.ts b/src/utilities/index.test.ts index 2285332..1f7e205 100644 --- a/src/utilities/index.test.ts +++ b/src/utilities/index.test.ts @@ -137,10 +137,10 @@ describe("parseFormData", () => { const requestFormDataSpy = vi.spyOn(request, "formData"); const blob = new Blob(["Hello, world!"], { type: "text/plain" }); const mockFormData = new FormData(); - mockFormData.append("formData", blob); + mockFormData.append("file", blob); requestFormDataSpy.mockResolvedValueOnce(mockFormData); - const data = await parseFormData<{ formData: any }>(request); - expect(data.formData).toBeTypeOf("object"); + const data = await parseFormData<{ file: Blob }>(request); + expect(data.file).toBeTypeOf("object"); }); }); diff --git a/test-apps/react-router/app/routes/home.tsx b/test-apps/react-router/app/routes/home.tsx index 9b86379..96f9b3f 100644 --- a/test-apps/react-router/app/routes/home.tsx +++ b/test-apps/react-router/app/routes/home.tsx @@ -1,5 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod"; -import { Form, useFetcher } from "react-router"; +import { type ClientActionFunctionArgs, Form, useFetcher } from "react-router"; import { type ActionFunctionArgs, type LoaderFunctionArgs, @@ -47,7 +47,12 @@ export const action = async ({ request }: ActionFunctionArgs) => { console.log(formData); return { result: "success" }; }; - +export const clientAction = async ({ + request, + serverAction, +}: ClientActionFunctionArgs) => { + return { result: "success" }; +}; export default function Index() { const fetcher = useFetcher(); const methods = useRemixForm({