Skip to content

Commit

Permalink
Fixed issue with typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
AlemTuzlak committed Jan 21, 2025
1 parent 71f7ed5 commit 3d60844
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/hook/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import {
type FormMethod,
type SubmitFunction,
useActionData,
useHref,
useNavigation,
useSubmit,
useHref,
} from "react-router";

import { createFormData } from "../utilities";
Expand Down Expand Up @@ -225,7 +225,7 @@ export const useRemixForm = <T extends FieldValues>({
onInvalidHandler,
)(e);
},
[methods.handleSubmit, submitHandlers, onSubmit, onInvalid],
[methods.handleSubmit, submitHandlers, onSubmit, onInvalid, basename],
);

const hookReturn = useMemo(
Expand All @@ -242,7 +242,11 @@ export const useRemixForm = <T extends FieldValues>({
return hookReturn;
};

export type UseRemixFormReturn = ReturnType<typeof useRemixForm>;
export type UseRemixFormReturn<T extends FieldValues> = UseFormReturn<T> & {
handleSubmit: ReturnType<typeof useRemixForm>["handleSubmit"];
reset: ReturnType<typeof useRemixForm>["reset"];
register: ReturnType<typeof useRemixForm>["register"];
};

interface RemixFormProviderProps<T extends FieldValues>
extends Omit<UseFormReturn<T>, "handleSubmit" | "reset"> {
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

Expand Down
9 changes: 7 additions & 2 deletions test-apps/react-router/app/routes/home.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 3d60844

Please sign in to comment.