Example input draw value and make console log with this value when you click the submit button with React

0

By clicking the submit button I want to take the value of input and make console log of the value entered by the user! I think it's simple but what I'm trying to do is more complex, but it's going to be implemented right now!

Made with React

  • Input
  • Send button
asked by anonymous 04.07.2018 / 17:28

1 answer

2

In your <input /> tag you should 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);
}
    
04.07.2018 / 19:16