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

How to get button title?

Im trying to get my button name , from the event, but I’m not finding it

my button call(JSX) code:

   {...}
 <View style={styles.container}> 
    {userForm.map((item) => (       
      <Button title = {item.name.slice(7)} key = {item.info.uuid} onPress = {handleClick} />    
    ))}
    
    </View>
      {...}

My handle click constant where I try to get the button title:

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

  const handleClick = (e) => {
    var objeto = e.currentTarget.title;
    console.log(objeto);

    };

someone knows where or how to get my button title ?

>Solution :

e.currentTarget gives you the button element that is rendered in your screen. You could access its text content by using e.currentTarget.textContent or you can pass the title as an argument directly to your handleClick function:

<Button title = {item.name.slice(7)} key = {item.info.uuid} onPress = {handleClick(item.name.slice(7))} />


  const handleClick = (buttonTitle) => (e) => {
    console.log(buttonTitle)
    };
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