admin管理员组文章数量:1392088
I have the following code which creates a text area.
interface IReceiverProps {
receivedMessage: string;
topic: string;
}
export default class Receiver extends React.Component<IReceiverProps, {}> {
render() {
var textAreaStyle = {
width: 1300,
height: 450,
border: '3px solid #cccccc',
padding: '5px',
fontFamily: 'Tahoma, sans-serif',
overflow: 'auto',
marginLeft: '10px'
}
return (
<textarea style={textAreaStyle} value={this.props.receivedMessage}/>
);
}
}
This received message is passed by another ponent. How can I append the receivedMessage one below another in this text area? Any help would be much appreciated.
I have the following code which creates a text area.
interface IReceiverProps {
receivedMessage: string;
topic: string;
}
export default class Receiver extends React.Component<IReceiverProps, {}> {
render() {
var textAreaStyle = {
width: 1300,
height: 450,
border: '3px solid #cccccc',
padding: '5px',
fontFamily: 'Tahoma, sans-serif',
overflow: 'auto',
marginLeft: '10px'
}
return (
<textarea style={textAreaStyle} value={this.props.receivedMessage}/>
);
}
}
This received message is passed by another ponent. How can I append the receivedMessage one below another in this text area? Any help would be much appreciated.
Share Improve this question asked Sep 27, 2016 at 5:47 AnOldSoulAnOldSoul 4,20714 gold badges67 silver badges136 bronze badges 3- some working code? jsfiddle or jsbin? – Fazal Rasel Commented Sep 27, 2016 at 5:55
- There are few dependencies so its hard to get it there. In the above code, I'm just adding the received message to value of text area. This obviously will replace the message everytime. So how should this be handled? How can I append it? – AnOldSoul Commented Sep 27, 2016 at 6:13
-
how about using a
div
undertextarea
and on saving sending bined data? – Fazal Rasel Commented Sep 27, 2016 at 6:20
1 Answer
Reset to default 3Use a state called textMessage.
constructor(props) {
super(props);
this.state = {
textMessage: props.receivedMessage
};
}
In ponentWillReceiveProps, append to textMessage.
ponentWillReceiveProps(nextProps) {
if (nextProps.receivedMessage !== this.props.receivedMessage) {
this.setState({
textMessage: `${this.state.textMessage}\n{nextProps.receivedMessage}`
});
}
}
Bind to textMessage.
<textarea style={textAreaStyle} value={this.state.textMessage} />
本文标签: javascriptHow to append text to text area created in React JSStack Overflow
版权声明:本文标题:javascript - How to append text to text area created in React JS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744781761a2624755.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论