2
How do I pick up something that I typed in an input text, and when I press a "Send" button, I send that text somewhere in my code, like how we use 'this.state.algumaCoisa'... Follow the code:
render(){
return(
<div className="container">
<div className="box box-primary direct-chat direct-chat-primary ">
<Chat />
<div nameClass="direct-chat-msg right">
<div className="direct-chat-info clearfix">
<span className="direct-chat-name pull-right">TEXTO AQUI</span>
<span className="direct-chat-timestamp pull-right">TEXTO AQUI</span>
</div>
<img className="direct-chat-img-right" alt="message user image"/>
</div>
<div className="box-footer">
<div className="input-group">
<input
ref="topic"
type="text"
name="message"
placeholder="Type your message here..."
className="form-control"/>
<span className="input-group-btn">
<button type="button" className="btn btn-flat btn-primary">Send</button>
</span>
</div>
</div>
</div>
</div>
);
}
But if I want to, take what I type in the input text, and when clicking on the "Send" button, send this typed content to (for example), a <div> or <span> or <H1> in the code? I tried to use {this.state.text}, but it only appears what I am typing in the input simultaneously: <div classname="direct-chat-text">{this.state.text}</div>
– Henrique Hermes
@Henriquehermes when you say "send this typed content" you mean show inside a
div
on the same or another component?– Sergio
To explain further, I uploaded a print of how I would like the code to perform: https://imgur.com/iGDZ1Z4
– Henrique Hermes
@Henriquehermes the logic should be: write > click send > write to server > ajax sucess does state update > render shows new message. If this component is responsible for updating chatbox the logic is optimistic and I think it is better to be done elsewhere
– Sergio