TanStackT
TanStack2y ago
1 reply
foolish-indigo

Multiple request using useMutation

Hi everyone,

Let's say I have a todo list (an array of objects), and I want to send a POST request to a specific endpoint to create a new todo. The endpoint accepts an object, not an array.

Currently, what I do is loop through each todo and call the function like this:
todos.forEach(async (todo) => await createTodoHandler(todo));

How can I refactor this using useMutation, and what is the best way to handle multiple calls similar to the previous example?
Was this page helpful?