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

Madushika Perera picture Madushika Perera · Mar 10, 2017 · Viewed 14.1k times · Source

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?

Answer

Sole Valero picture Sole Valero · Jul 28, 2017

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

this.inputtext.inputRef.value