1 回答

TA貢獻1829條經驗 獲得超13個贊
您可以使用回調,而不是直接從函數體上的結果檢查屬性,如下所示onErroraddingContactError
const _onCreateUserRelationError = React.useCallback((error: ApolloError) => {
console.log('this is the error', error);
Alert.alert(error.message.includes('already exists') ? 'Contact Already Exists' : 'Unable to Add Contact');
}, []);
const [
createUserRelationMutation,
{
data: addingContactData,
loading: addingContactLoading,
called: isMutationCalled,
},
] = useCreateUserRelationMutation({
onCompleted: () => {
Alert.alert('Contact Added');
},
onError: _onCreateUserRelationError
});
注: 使用 記住組件以避免此組件的不必要重新渲染React.memo
添加回答
舉報