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

190
Views
Passing a value to onPress to trigger a function

  const change = (e) => {
    console.log(e)
    //Firebase.database().ref(`userSubject/${subjectTaken.user}/${subjectTaken.id}/topics/${name}/`).update({"completed": !completed})
  }


  return (
    <View style={styles.page}  >
      <Header type="dark-profile" title={subjectTaken.name} desc="Here is your progress. You can do this!" onPress={() => navigation.goBack()}/>
      <View>
        {topic.map(item => {
          if(item.completed === true) {
            return <TodoBox text={item.lesson} type={true} onPress={() => console.log("YEY")} />
          } else {
            const name = item.lesson
            return (
              
              <TodoBox text={item.lesson} type={false} onPress={(name) => {this.change(item.lesson)}} />
            )
          }
        })}
      </View>
    </View>
  )
}


I am wondering how i can pass the variable item.lesson to the function that i inserted on onpress... log gives me undefined why

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In this snippet, you are passing name as a parameter, so the function does not know about item.

Also, it looks like the onChange function requires an event as a parameter. So, changing the following line:

<TodoBox text={item.lesson} type={false} onPress={(name) => {this.change(item.lesson)}} />

to this:

<TodoBox text={item.lesson} type={false} onPress={(e) => {this.change(e)}} />

might fix this.

Finally, please try to the complete code if possible.

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!