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

242
Views
How can I pass a value to a function when onPress is pressed in Reactnative?

I'm using Reactnaitve When onPress is triggered, the photosModalControl function is executed and I want to get the value first, and I also want to execute setUploadPhotos. But when I use my code, I get the value, but setUploadPhotos is not executed. How do I fix the code?

this is my code

const photosModalControl = (value: string) => () =>  {
    console.log(value);
    setUploadPhotos(prevState => !prevState);
};


<Pressable 
onPress={photosModalControl("first")}
>
</Pressable>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If im not mistaken, shouldn't you set up your function like this:

const someFunction = (variable: type) => { functions stuff}

you doubled up and put:

const someFunction = (variable: type) = () => { functions stuff}

about 4 years ago · Juan Pablo Isaza Report

0

The way you are passing the function in the onPress will result in that function call on render. Instead use this:

    const photosModalControl = (value: string) => () =>  {
        console.log(value);
        setUploadPhotos(prevState => !prevState);
    };


    <Pressable onPress={()=>photosModalControl("first")}>Button</Pressable>

This way you can pass any number of arguments to your function

about 4 years ago · Juan Pablo Isaza 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!