@beignet/react-hook-form 0.0.55 → 0.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @beignet/react-hook-form
2
2
 
3
+ ## 0.0.57
4
+
5
+ ## 0.0.56
6
+
7
+ ### Patch Changes
8
+
9
+ - e00c302: Use direct React Query options and declarative invalidation in generated components, with guidance for extracting shared client behavior.
10
+
3
11
  ## 0.0.55
4
12
 
5
13
  ## 0.0.54
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beignet/react-hook-form",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "type": "module",
5
5
  "description": "React Hook Form integration for Beignet with Standard Schema support",
6
6
  "main": "./dist/index.js",
@@ -40,39 +40,37 @@ contracts, use cases, tests, and components.
40
40
 
41
41
  ## Form Pattern
42
42
 
43
+ Pass callbacks inside `mutationOptions`; overwriting its returned `onSuccess`
44
+ bypasses declarative invalidation.
45
+
43
46
  ```tsx
44
47
  "use client";
45
48
 
46
- import { useMutation, useQueryClient } from "@tanstack/react-query";
49
+ import { useMutation } from "@tanstack/react-query";
47
50
  import { rootFormError } from "@beignet/react-hook-form";
48
51
  import { rhf } from "@/client/forms";
49
- import { createTodo } from "@/features/todos/contracts";
50
- import {
51
- createTodoMutationOptions,
52
- invalidateTodos,
53
- } from "@/features/todos/client/queries";
52
+ import { rq } from "@/client";
53
+ import { createTodo, listTodos } from "@/features/todos/contracts";
54
54
 
55
55
  const createTodoForm = rhf(createTodo);
56
56
 
57
57
  export function CreateTodoForm() {
58
- const queryClient = useQueryClient();
59
58
  const form = createTodoForm.useForm({
60
59
  defaultValues: { title: "" },
61
60
  });
62
61
 
63
- const mutation = useMutation({
64
- ...createTodoMutationOptions(),
65
- onSuccess: () => {
66
- form.reset();
67
- invalidateTodos(queryClient);
68
- },
69
- onError: (error) => {
70
- form.setError(
71
- "root",
72
- rootFormError(error, "Could not create the todo."),
73
- );
74
- },
75
- });
62
+ const mutation = useMutation(
63
+ rq(createTodo).mutationOptions({
64
+ invalidates: () => [rq(listTodos).contractFilter()],
65
+ onSuccess: () => form.reset(),
66
+ onError: (error) => {
67
+ form.setError(
68
+ "root",
69
+ rootFormError(error, "Could not create the todo."),
70
+ );
71
+ },
72
+ }),
73
+ );
76
74
 
77
75
  return (
78
76
  <form