K.Palyanichka K.Palyanichka -4 years ago 145
React JSX Question

Can not type any text in textarea

i can not type any text in my text areas.
I can not modify my default text.

How i can solve my problem ?

class SomeClass extends Component{
constructor(props){
super(props)
this.state = {data:[]}

}
handleChange(e, media_id){
var newState = $.each(this.props.data, function() {
if (this.media_id == media_id) {
this.text = e.target.value }
});
this.setState({data:newState})
};
render(){
return(
<div className="col s9 m9 cards-container">
{this.props.data.map(item =>
<div className="input-field">
<textarea
placeholder="Описание с тегами" ref="tags"
className="materialize-textarea" value={ item.text }
onChange={this.handleChange.bind(this, item.media_id)}
/>
</div>)})}
}

Answer Source

Reverse the order of your parameters to handleChange:

handleChange(media_id, e)

Because of how the handleChange is bound, the parameters are going to be in the reverse order:

this.handleChange.bind(this, item.media_id)

That returns a partially applied function where item.media_id is its first parameter. The eventual Event object that is passed when onChange happens will be the second parameter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download