Repository navigation
Replies: 2 comments
|
0 replies
|
For the dynamic account-ID case, make the shared options a plain factory and call that from both hooks. For example, const uploadOptions = (accountId: string) => mutationOptions({ mutationKey: ['upload', accountId] as const, mutationFn: (file: File) => upload(accountId, file) }). The uploading component uses useMutation(uploadOptions(accountId)). A separate status component uses useIsMutating({ mutationKey: uploadOptions(accountId).mutationKey, exact: true }). This keeps key construction in one place and the status component doesn't need its own mutation hook. Drop exact when you intentionally want prefix matching for additional suffixes, or filter by ['upload'] for an account-wide aggregate across all IDs. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
This is a bit of a follow-up to #2304.
Let's consider an example like this:
Right now, if I don't want to hard code the
mutationKeytwice I have to save it outside of the composable so it can be shared.I would like the mutation composable to be the single source of truth and expose the
mutationKeyforuseIsMutatinganduseMutationStateto reuse. It could be used like this:This would be especially useful when the
mutationKeyhas dynamic parts.While writing this I even thought of a possible extension of this concept in the future:
This would allow the
useMutationStateto inherit its typings from the passeduseMutation.All reactions