I have a TextArea object that will not allow new text to be entered. Initially I had tried this without the constructor, but would get areas when I would try to call my on change method because it was not bound to this. Adding the constructor to bind the onChange method disallows me from entering text.
class TextAreaCounter extends React.Component{
constructor(props) {
super(props);
this._textChange = this._textChange.bind(this);
}
getInitialState() {
return {
text: this.props.text,
};
}
_textChange(ev) {
this.setState({
text: ev.target.value,
});
}
render() {
return React.DOM.div(null,
React.DOM.textarea({
value: this.props.text,
onChange: this._textChange,
}),
React.DOM.h3(null, this.props.text.length)
);
}
}
TextAreaCounter.PropTypes = {
text: React.PropTypes.string,
}
TextAreaCounter.defaultProps = {
text: '',
}
ReactDOM.render(
React.createElement(TextAreaCounter, {
text: "billy",
}),
document.getElementById("app")
);