Skip to content

Commit b47b6fc

Browse files
committed
Add missing UseMutationStateOptions to UseMutation pseudo type
1 parent 07a430b commit b47b6fc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

query-old/docs/api/created-api/hooks.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ The query arg is used as a cache key. Changing the query arg will tell the hook
9191
#### Signature
9292

9393
```ts
94-
type UseMutation<Definition> = () => [UseMutationTrigger<Definition>, UseMutationResult<Definition>];
94+
type UseMutation<Definition> = (
95+
UseMutationStateOptions<Definition>
96+
) => [UseMutationTrigger<Definition>, UseMutationResult<Definition> | SelectedUseMutationResult];
97+
98+
type UseMutationStateOptions<Definition> = {
99+
// A method to determine the contents of `UseMutationResult`
100+
selectFromResult?: (state, defaultMutationStateSelector) => SelectedUseMutationResult extends Record<string, any>
101+
}
95102

96103
type UseMutationTrigger<Definition> = (
97104
arg: ArgTypeFrom<Definition>
@@ -122,6 +129,16 @@ type UseMutationResult<Definition> = {
122129
};
123130
```
124131
132+
:::tip
133+
134+
The generated `UseMutation` hook will cause a component to re-render by default after the trigger callback is fired as it affects the properties of the result. If you want to call the trigger but don't care about subscribing to the result with the hook, you can use the `selectFromResult` option to limit the properties that the hook cares about.
135+
136+
Passing a completely empty object will prevent the hook from causing a re-render at all, e.g.
137+
```ts
138+
selectFromResult: () => ({})
139+
```
140+
:::
141+
125142
- **Returns**: a tuple containing:
126143
- `trigger`: a function that triggers an update to the data based on the provided argument. The trigger function returns a promise with the properties shown above that may be used to handle the behaviour of the promise.
127144
- `mutationState`: a query status object containing the current loading state and metadata about the request

0 commit comments

Comments
 (0)