I got this error while trying to prefetch the data
react_query__WEBPACK_IMPORTED_MODULE_5__.QueryClient.prefetchQuery is not a function
This is my code
const formReducer = (state, event) => {
return {
...state,
[event.target.name]: event.target.value,
};
};
export default function InsertForm() {
const [formData, setFormData] = useReducer(formReducer, {});
const addMutation = useMutation(addOneUser,{
//fonction efa vita de mandeha ho azy le onsuccess
onSuccess: async () =>{
//This should work, here the model is the user and the method for fetching the response is getUser
await QueryClient.prefetchQuery(['user'], getUser);
}
})
const handleSubmit = (e) => {
e.preventDefault();
if(Object.keys(formData).length == 0) return console.log("Tsy misy donnes ao @ le formulaire");
let{nom,
mail,
dept,
status }= formData;
const model={
nom,
avatar:`https://randomuser.me/api/portraits/men/${Math.floor(Math.random()*10)}.jpg`,
mail,
dept,
status:status ?? "Active"
}
console.log(model,"mandeha tsara ny modelisation");
addMutation.mutate(model);
};
I try to mutate the data through a model, I don't know what I've done wrong. I'm new to NextJs