@beignet/react-hook-form 0.0.54 → 0.0.56
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 +8 -0
- package/package.json +1 -1
- package/skills/forms/SKILL.md +18 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @beignet/react-hook-form
|
|
2
2
|
|
|
3
|
+
## 0.0.56
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e00c302: Use direct React Query options and declarative invalidation in generated components, with guidance for extracting shared client behavior.
|
|
8
|
+
|
|
9
|
+
## 0.0.55
|
|
10
|
+
|
|
3
11
|
## 0.0.54
|
|
4
12
|
|
|
5
13
|
## 0.0.53
|
package/package.json
CHANGED
package/skills/forms/SKILL.md
CHANGED
|
@@ -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
|
|
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 {
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
form.reset()
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|