I have problem with changing value of input during onChange,
handleChange(event){
this.setState({
value: event.target.value
});
}
render(){
return(
<div className={s.root}>
<div className={s.container}>
<label className={s.captionLabel}>{this.props.caption}</label>
<input className={this.props.modal? s.modalTextInput : s.textInput} onChange={this.handleChange} value={this.state.value} ref="inp" disabled={!this.state.isChecked} type="text" />
<label className={s.unitLabel}>{this.props.unit}</label>
<input className={s.boxInput} type="checkbox" checked={this.state.isChecked} onChange={this.toggleChange.bind(this)}/>
</div>
</div>
)
}
I am still getting error message
Uncaught TypeError: Cannot read property 'setState' of undefined
I tried onChange={this.handleChange.bind(this} , after this I didn't receive this error message but I couldn't change value of input. In extract of event.target.value I am getting value like a 1,01,02 and so on.... but value don't change anymore (I just cant overwrite value in input ). So any tips what I have to do?
es6 classmethod for the component, you'll have to manuallybind this. Regarding input value, if you console logthis.state.valueon render and type something on your input, what value will be logged ?super(props),value: '0'andthis.handleChange=this.handleChange.bind(this)handleChange(event)commentthis.setStateand writeconsole.log(event). Type in anything and see what logs in your debugger console.Object { dispatchConfig: Object, _targetInst: Object, nativeEvent: input, type: "change", target: <input.Inputs_modalTextInput_2d6>, currentTarget: <input.Inputs_modalTextInput_2d6>, eventPhase: 3, bubbles: true, cancelable: false, timeStamp: 1469599236447, 6 and next… }what exactly am i looking for?