Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

react native onPress and props

On react native, why can I call the return function to pass a prop, but when passing it in a composed function it won’t work?

This works

           const pop = props.onPress;
...
         <TouchableOpacity style={styles.okButton} onPress={pop}>

But,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 function closee() {
  console.log('aaadsedf');
  props.onPress;
 }
...
      <TouchableOpacity style={styles.okButton} onPress={closee}>

shows log working ok, but doesnt trigger the props.onPress

So how to properly call the onPress?
how to properly pass the composed function?

>Solution :

You need to call it like:

 function closee() {
  console.log('aaadsedf');
  props.onPress();
 }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading