query-key-factory
query-key-factory copied to clipboard
New createMutationKeys doesn't work for mutations with arguments
I first tried to follow the standard practice like for parametrized queries
export const todos = createMutationKeys('todos', {
prop: (input: string) => ({
mutationKey: [input],
mutationFn: () => Promise.resolve(input),
}),
});
...
const {mutate} = useMutation(todos.prop('hello');
// mutate has type UseMutateFunction<string, unknown, undefined, unknown>
mutate() // fails - arguments not provided (expected undefined)
mutate(undefined) // ok, returns void instead of Promise<string>
I also tried
export const todos = createMutationKeys('todos', {
prop: {
mutationKey: null,
mutationFn: (input: string) => Promise.resolve(input),
},
});
...
const {mutate} = useMutation(todos.prop);
// mutate has type UseMutateFunction<unknown, unknown, void, unknown>
mutate('hello') // fails - string is not assignable to 'void'
mutate() // ok, returns void instead of Promise<string> (but we haven't passed in the input string anywhere)
Neither gives me a workable type where I can pass in an argument. I could try to work on it myself but I'm not super familiar with this library yet.