变更操作(useMutation)
import { useMutation } from '@iostore/react';
const createTodo = useMutation({ mutationFn: (payload: { title: string }) => fetch('/api/todos', { method: 'POST', body: JSON.stringify(payload), }).then((r) => r.json()),});- 写操作成功后优先
invalidateQueries,不要手写猜测式同步。 - 需要秒回时可使用乐观更新,再在失败时回滚。
- 区分
isPending(提交中)与查询态字段,避免 UI 状态混淆。