本页还没有译文
本页 11 段还没译成日本語,下面显示的是英文原文。Ensure correct order of inference-sensitive properties in useMutation()
还没翻译译自英文(tanstack.com)本页 11 段都还没译
For the following functions, the property order of the passed in object matters due to type inference:
useMutation()
The correct property order is as follows:
onMutateonErroronSettled
All other properties are insensitive to the order as they do not depend on type inference.
Rule Details
Examples of incorrect code for this rule:
/* eslint "@tanstack/query/mutation-property-order": "warn" */
import { useMutation } from '@tanstack/react-query'
const mutation = useMutation({
mutationFn: () => Promise.resolve('success'),
onSettled: () => {
results.push('onSettled-promise')
return Promise.resolve('also-ignored') // Promise<string> (should be ignored)
},
onMutate: async () => {
results.push('onMutate-async')
await sleep(1)
return { backup: 'async-data' }
},
onError: async () => {
results.push('onError-async-start')
await sleep(1)
results.push('onError-async-end')
},
})Examples of correct code for this rule:
/* eslint "@tanstack/query/mutation-property-order": "warn" */
import { useMutation } from '@tanstack/react-query'
const mutation = useMutation({
mutationFn: () => Promise.resolve('success'),
onMutate: async () => {
results.push('onMutate-async')
await sleep(1)
return { backup: 'async-data' }
},
onError: async () => {
results.push('onError-async-start')
await sleep(1)
results.push('onError-async-end')
},
onSettled: () => {
results.push('onSettled-promise')
return Promise.resolve('also-ignored') // Promise<string> (should be ignored)
},
})Attributes
- ✅ Recommended
- 🔧 Fixable
AI 翻译查看英文原文