Skip to content

Commit 8a314ff

Browse files
authored
Merge pull request #183 from code-forge-io/fix/rhf-7.75-setvalues
feat: support react-hook-form 7.75.0 (isReady + setValues) (#180)
2 parents 8ae46d2 + 056c49a commit 8a314ff

5 files changed

Lines changed: 41 additions & 9 deletions

File tree

‎.changeset/rhf-7-75-compat.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"remix-hook-form": minor
3+
---
4+
5+
Fix type errors with react-hook-form 7.75.0. `FormState` gained an `isReady` field and `UseFormReturn` gained `setValues` in 7.75; the wrapped `formState` now exposes `isReady` (preserving the lazy getter behavior) and `setValues` flows through the hook's return type. Resolves the "Property 'setValues'/'isReady' is missing" errors (#180).

‎package-lock.json‎

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"peerDependencies": {
8686
"react": "^18.2.0 || ^19.0.0",
8787
"react-dom": "^18.2.0 || ^19.0.0",
88-
"react-hook-form": "^7.55.0",
88+
"react-hook-form": "^7.75.0",
8989
"react-router": ">=7.5.0"
9090
},
9191
"readme": "https://github.com/code-forge-io/remix-hook-form#readme",
@@ -104,7 +104,7 @@
104104
"prettier": "^3.0.1",
105105
"react": "^18.2.0",
106106
"react-dom": "^18.2.0",
107-
"react-hook-form": "^7.51.0",
107+
"react-hook-form": "^7.75.0",
108108
"rollup": "^3.20.2",
109109
"rollup-plugin-typescript2": "^0.34.1",
110110
"tsup": "^8.3.5",

‎src/hook/index.test.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe("useRemixForm", () => {
5858
submitCount: 0,
5959
isLoading: false,
6060
errors: {},
61+
isReady: true,
6162
});
6263
expect(result.current.handleSubmit).toBeInstanceOf(Function);
6364
});
@@ -217,7 +218,10 @@ describe("useRemixForm", () => {
217218
await new Promise((resolve) => setTimeout(resolve, 0));
218219
});
219220

220-
expect(renderCount()).toBe(1);
221+
// react-hook-form >= 7.75 emits an extra formState notification per
222+
// validation cycle (two cycles here), so the baseline render count is 3.
223+
// The optimization still holds: this stays below the subscribed case below.
224+
expect(renderCount()).toBe(3);
221225
});
222226

223227
it("should re-render on validation if isValidating is being accessed", async () => {
@@ -255,7 +259,10 @@ describe("useRemixForm", () => {
255259
await new Promise((resolve) => setTimeout(resolve, 0));
256260
});
257261

258-
expect(renderCount()).toBe(3);
262+
// Accessing isValidating subscribes to it, so each validation cycle
263+
// re-renders — 2 more than the unsubscribed case above (3 -> 5 on
264+
// react-hook-form >= 7.75, which raised the baseline by 2).
265+
expect(renderCount()).toBe(5);
259266
});
260267

261268
it("should not flash incorrect isSubmitting status", async () => {

‎src/hook/index.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ export const useRemixForm = <
187187
get errors() {
188188
return methods.formState.errors;
189189
},
190+
get isReady() {
191+
return methods.formState.isReady;
192+
},
190193
}),
191194
[methods.formState, isSubmittedSuccessfully, isSubmittingNetwork],
192195
);

0 commit comments

Comments
 (0)