Usemutation loops - useMutation on re-render/page loading

Hello,

I would like to register a new user on first connection.
What i do so far is :

  • Login using google/facebook signin
  • if the user already exists in my database i get the user information
  • if the user does not exist, i create the user

I use to use mutation during a action (like a click) but here i want to check if the user is in the database when they get to the homepage, if he does not exist i want to create it.
But i dont succeed to do it and the mutation just loop.
How can i use the useMutation without to be trigger at each rendering?
here is my code :

export default function HomeScreen({ navigation }) {
[adopter, setAdopter] = useState(false)

const realmUser = useUser()
const {data,loading,error} = getUserByEmail(“cyril.2moreau@gmailc.cs”)
const [addUserMutation, { dataAddUser, loadingAddUser, errorAddUser }] = addUser()

if (error) {alert(error.message)}
if (loading) {alert(“loading”)}
if (data && data?.getUserByEmail?.error){return Submission error! {data.getUserByEmail.error};}
if (data && data?.getUserByEmail?.email){console.log(JSON.stringify(data.getUserByEmail))}
/////// IT IS LOOPING ON THE NEXT LINE
IF THE USER DOES NOT EXIST I USE useMutation TO CREATE IT
if (data && !(data?.getUserByEmail?.userExists)){addUserMutation({variables:{email:“cyril.2moreau@gmailc.cs”, name:realmUser.profile.name}}); console.log(JSON.stringify(data.getUserByEmail))}

const changeProfile=()=>{
setAdopter(!adopter)
}
var footer =
var body =

if(adopter){
body =
footer=
}
var header =

return (

    <View style={styles.container}>
      <StatusBar style="auto" />
      {header}
        <View style={styles.content}>
          {body}
        </View>
          {footer}        
    </View>

);
}

Thank you for your help