react-nativeonpress

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,

 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();
     }