Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take inputs from <Input/> in react semantic UI

I've been trying to take inputs from an input field and i used refs(the usual way in react), But it doesn't seem to be working. The input i'm getting is undefined. This is my code:

sendMessage = () => {
   console.log(this.inputtext.value);
}

render(){
   return(
      <div>
         <Input ref={input => this.inputtext = input;} placeholder='message'/>
         <Button onClick={this.sendMessage}>Send</Button>
      </div>
   );
}

I need to take the inputs from the click event of the button. I can't figure out what's wrong. How can i get the input value properly?

like image 264
Madushika Perera Avatar asked Mar 10 '17 11:03

Madushika Perera


1 Answers

In your case, you can also get the input value through this code:

this.inputtext.inputRef.value
like image 90
Sole Valero Avatar answered Oct 06 '22 01:10

Sole Valero