Skip to content

Commit 1060815

Browse files
committed
docs: Update dc mutation usage
1 parent 587167c commit 1060815

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/react/data-connect/mutations.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ function Component() {
3333
}
3434
```
3535

36+
Additionally, you can provide a factory function to the mutation, which will be called with the mutation variables:
37+
38+
```tsx
39+
const createMovie = useDataConnectMutation((title: string) => createMovieRef({ title, reviewDate: Date.now() }));
40+
// ...
41+
createMovie.mutate("John Wick");
42+
```
43+
3644
## Invalidating Queries
3745

3846
The hook provides an additional [mutation option](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation) called `invalidate`. This option accepts a list of query references which will be automatically invalidated when the mutation is successful.
@@ -64,6 +72,18 @@ const createMovie = useDataConnectMutation(createMovieRef, {
6472

6573
In this case only the query reference `getMovieRef({ id: "1" })` will be invalidated.
6674

75+
### QueryKey
76+
77+
You can also provide a `QueryKey` to the invalidate array, for example:
78+
79+
```tsx
80+
const createMovie = useDataConnectMutation(createMovieRef, {
81+
invalidate: [
82+
["GetMovieById", { id: "1" }]
83+
],
84+
});
85+
```
86+
6787
## Overriding the mutation key
6888

6989
### Metadata

0 commit comments

Comments
 (0)