Hello all !
I’m wondering about this exercise : the create a controlled input , in react?
I completed it and submitted and it passed just fine, but when I enter the same code in a react fiddle (just to play around with the code more) it didn’t ?
I get some error: Uncaught typeError: cannot read the property ‘value’ of null.
Here’s the code (I added a ReactDOM.render() function just to see the results).
in the fiddle there is html code with an
class ControlledInput extends React.Component {
constructor(props) {
super(props);
this.state = {
input: ''
};
this.handleChange = this.handleChange.bind(this)
}
handleChange(event){
this.setState((state) => ({
input : event.target.value
}));
}
render() {
return (
<div>
<input value={this.state.input} onChange={this.handleChange}/>
<h4>Controlled Input:</h4>
<p>{this.state.input}</p>
</div>
);
}
};
ReactDOM.render(<ControlledInput/>,document.getElementById("containerinput"));
Thanks