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
添加回答
举报
