I have an input and a button
<input className="form-control" value={this.state.sentence} onChange={this.onChange}/>
<button type="button" onClick={this.handleSentence}></button>
I linked both functions in the constructor.
onChange(e) {this.setState({sentence: e.target.value});}
handleSentence(e) {console.log('string -->',this.state.sentence)}
in function handleSentence logreturns Cannot read property 'state' of null.
but in render(let{sentence}=this.state)returns the correct value, and also I see what I enter in the input
Here is the constructor:
class SentenceForm extends Component {
constructor(props) {
super(props)
this.state = {
sentence: '',
splitedSentenceArray:[]
}
this.onChange = this.onChange.bind(this);
this.onClick = this.handleSentence.bind(this);
}
source
share