[typescript] how to make first argument in mutation function required? #975
Answered
by
TkDodo
stefanprobst
asked this question in
General
-
hi, i am trying to make the first argument of the mutation function (i.e. import { useMutation, MutationConfig } from 'react-query';
type Todo = { title: string };
function createTodo(todo: Todo) {
return fetch('https://jsonplaceholder.typicode.com/posts/', {
method: 'post',
body: JSON.stringify(todo),
}).then((r) => r.json());
}
function useCreateTodo(config?: MutationConfig<Todo, Error, Todo>) {
return useMutation<Todo, Error, Todo>((todo) => createTodo(todo), config);
}
export default function Page() {
const [create] = useCreateTodo();
return (
<button
onClick={async () => {
// FIXME: this should require a Todo as the first argument, but it does not.
await create();
}}
>
Create
</button>
);
} |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Sep 26, 2020
Replies: 1 comment
-
FYI, I think this now tracked here: #1077 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
stefanprobst
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI, I think this now tracked here: #1077