For some reason the todo which i want to add don’ t work in todoForm
i did the same thing that Mosh did
here is my code : const TodoForm = () => {
const queryClient = useQueryClient();
const addTodo = useMutation<Todo, Error, Todo>({
mutationFn: (todo: Todo) =>
axios
.post(“https://jsonplaceholder.typicode.com/todos”, todo)
.then((res) => res.data),
onSuccess: (savedTodo, newTodo) => {
queryClient.setQueryData<Todo[]>(["todos"], (todos) => [
savedTodo,
...(todos || []),
]);
},
});
const ref = useRef(null)
if (ref.current && ref.current.value)
addTodo.mutate({
id: 0,
title: ref.current?.value,
completed: false,
userId: 1,
});
}}