Reactjs 如何避免阿波罗突变钩的突变破坏?
我正在包装来自Reactjs 如何避免阿波罗突变钩的突变破坏?,reactjs,typescript,eslint,react-apollo,Reactjs,Typescript,Eslint,React Apollo,我正在包装来自react apollo的usemotation钩子,以便每次使用变异时都能将错误发送到Sentry: import { useMutation } from '@apollo/react-hooks' import { DocumentNode } from 'graphql' import { MutationHookOptions } from 'react-apollo' type UseMutationWithSentryErrorsProps = { refetc
react apollo
的usemotation
钩子,以便每次使用变异时都能将错误发送到Sentry
:
import { useMutation } from '@apollo/react-hooks'
import { DocumentNode } from 'graphql'
import { MutationHookOptions } from 'react-apollo'
type UseMutationWithSentryErrorsProps = {
refetch: MutationHookOptions<any, Record<string, any>>
from: string
mutation: DocumentNode
}
export const useMutationWithSentryErrors = ({
refetch,
from,
mutation
}: UseMutationWithSentryErrorsProps) => {
const response = useMutation(mutation, refetch)
const [_apolloMutation, { error: mutationError }] = response
if (mutationError) {
captureException(mutationError, {
info: 'There was an error fetching data.',
from
})
}
return response
}
这一行的问题在于:
const [_apolloMutation, { error: mutationError }] = response
我得到一个变量未读取
错误。如果不访问变异,我无法访问响应错误,但我不是在这个包装函数中使用变异,而是在我真正使用它的地方使用变异。我尝试了经典的。
语法,但仍然有相同的错误。您可以这样做:
const [, { error: mutationError }] = response
注意逗号我选择它作为额外的检查
if(apolloMutation&&mutationError){等。
const [, { error: mutationError }] = response