Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
React Native - why do functions trigger automaticly?

Let me start up by saying that i just started learning React Native, and for that, i will try to be as explicite as possible.

Context:

i'm trying to create a simple sign in/sign up page, i have a home screen that contains 2 Inputs with React State (userName and password) that i need to pass to a service when i press on a button, so the code look like this :
function HomeScreen(props) {
  const [userName, onChangeUserNameText] = React.useState(null);
  const [password, onChangePasswordText] = React.useState(null);
  ...
  return (
        <TextInput 
          ...
          onChangeText={onChangeUserNameText}
          value={userName}
        />
        <TextInput
          ...
          onChangeText={onChangePasswordText}
          value={password}
        />
        <Button
          ...
          onPress={SignIn(userName, password)}
        />
    )

the SignIn(...) method is exported from another file that i called home.service that should handle the communiation between my home screen and the API calls, i also put some logs in that function.

Problem:

for some reason, whenever i load the application, or updated any of my inputs, the function that should be executed when i press on the sing in button is getting executed

on load

enter image description here

on Change Text

enter image description here

what am i missing here ?

Edit/Conclusion :

Tank you @Robin Zigmond, the porblem was as this gentelman said, in the way i called my functions in the onPress event:

<Button
    ...
    onPress={() => SignIn(userName, password)}
/>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to add a callback, otherwise SignIn will keep executing:

function HomeScreen(props) {
  const [userName, onChangeUserNameText] = React.useState(null);
  const [password, onChangePasswordText] = React.useState(null);
  ...
  return (
        <TextInput 
          ...
          onChangeText={onChangeUserNameText}
          value={userName}
        />
        <TextInput
          ...
          onChangeText={onChangePasswordText}
          value={password}
        />
        <Button
          ...
          onPress={() => SignIn(userName, password)}
        />
    )
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!