How to type object like this as props
Heyy I play a little with trpc and optimistic updates and I wonder how can I type object like this when I pass it as props.
then
const addTodo = api.todos.createTodo.useMutation({
async onMutate(newTodo) {
// Cancel outgoing fetches (so they don't overwrite our optimistic update)
await utils.todos.getAllTodos.cancel();
// Get the data from the queryCache
const prevData = utils.todos.getAllTodos.getData();
// Optimistically update the data with our new post
utils.todos.getAllTodos.setData(
undefined,
(old) => [...(old as Todo[]), newTodo] as Todo[]
);
// Return the previous data so we can revert if something goes wrong
return { prevData };
},
onError(err, newPost, ctx) {
// If the mutation fails, use the context-value from onMutate
utils.todos.getAllTodos.setData(undefined, ctx?.prevData);
},
onSettled() {
// Sync with server once mutation has settled
void utils.todos.getAllTodos.invalidate();
},
});const addTodo = api.todos.createTodo.useMutation({
async onMutate(newTodo) {
// Cancel outgoing fetches (so they don't overwrite our optimistic update)
await utils.todos.getAllTodos.cancel();
// Get the data from the queryCache
const prevData = utils.todos.getAllTodos.getData();
// Optimistically update the data with our new post
utils.todos.getAllTodos.setData(
undefined,
(old) => [...(old as Todo[]), newTodo] as Todo[]
);
// Return the previous data so we can revert if something goes wrong
return { prevData };
},
onError(err, newPost, ctx) {
// If the mutation fails, use the context-value from onMutate
utils.todos.getAllTodos.setData(undefined, ctx?.prevData);
},
onSettled() {
// Sync with server once mutation has settled
void utils.todos.getAllTodos.invalidate();
},
});then
const CreateTodo = ({ addTodo }: ???) => {}const CreateTodo = ({ addTodo }: ???) => {}