useOptimisticAction type errors #127
-
Im testing out the useOptimisticAction hook and have a little confusion around why i'm receiving type errors. Im just making a simple todo application. There are a list of todos and the user does a createTodo action that will update the list of todos. async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export const createTodo = action(schema, async ({ title }) => {
await sleep(1000);
const todo = await prisma.todo.create({
data: { title },
});
revalidatePath('/');
return todo;
}); const { execute, optimisticData, status } = useOptimisticAction(
createTodo,
todos,
(state, newTodo) => [...state, newTodo]
); {optimisticData.map(todo => (
<p key={todo.id}>
{todo.title}
</p>
))} in my useOptimisticAction hook i get a type error on "todos" and on "state". Reading the docs it says that it must match the return value of my action. My action just returns the one todo, and the intitial state is all of the todos that are fetched by the server. The optimistic updates in my code work as expected, Im just confused mostly on the type errors im receiving. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Can you please provide a link to a GitHub repo/StackBlitz env with a reproduction example? Thanks! |
Beta Was this translation helpful? Give feedback.
Implemented in v7.0.0-next.43.
Updated documentation can be found here.