Is it possible to extract useMutation from the component/page file in Next.js?
I would like to define all the useMutations and useQueries (like updateUser, deleteUser, createUser, getUsers, getUser) together inside a UserAPI.ts file. I found the following example where they have extracted them from the main component: https://v2.mantine-react-table.com/docs/examples/editing-crud
Editing CRUD Mantine React Table Example
Learn how to use editing and all the CRUD functionality of Mantine React Table
7 Replies
dependent-tanOP•2y ago
This is the error I am getting.
evident-indigo•2y ago
Did you read the error message?
dependent-tanOP•2y ago
Yes, of course. But in the example I linked in the first message it looks like they have defined the useMutations like useCreateUser and useUpdateUser outside of the main component if I am not mistaken. So I was wondering how they did it? Or if it is outdated?
evident-indigo•2y ago
And what does your code look like? Is it really the same?
dependent-tanOP•2y ago
This is the code I have in my EmployeeAPI.ts:
This is how I call the function in my React Table using a modal:
evident-indigo•2y ago
This is not allowed. You are calling a hook in a callback
Now read the error message again
dependent-tanOP•2y ago
Okay, I got it working now, thank you for your help!!