Example input take value and log console with this value when you click send button with React

Asked

Viewed 94 times

0

By clicking the send button I want to take the input value and log console the value entered by the user! I think it’s simple but what I’m trying to do is more complex but will serve to implement what I need!

Made with React

  • Input
  • Send button

1 answer

2


Tag <input /> must have the refs attribute and also create a button to trigger a function. Example

<input type='text' ref='nome' />
<button onClick={() => this.handleClick }>Enviar</button>

Create the function handleClick()

handleClick(){
 const value = this.refs.nome.value;
 console.log(value);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.