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?
In your case, you can also get the input value through this code:
this.inputtext.inputRef.value