修改 Mutations
function App() {
const mutation = useMutation({
mutationFn: (newTodo) => {
return axios.post('/todos', newTodo)
},
})
return (
<div>
{mutation.isPending ? (
'正在添加待办事项...'
) : (
<>
{mutation.isError ? (
<div>发生错误:{mutation.error.message}</div>
) : null}
{mutation.isSuccess ? <div>待办事项已添加!</div> : null}
<button
onClick={() => {
mutation.mutate({ id: new Date(), title: '洗衣服' })
}}
>
创建待办事项
</button>
</>
)}
</div>
)
}重置变更状态
变更副作用
连续变更
Promise
重试
持久化变更
持久化离线变更
变更作用域
进一步阅读
最后更新于