You are not using the current state for the state update. This means the updater function is not needed and you should just be using an object.
handleChange(event) {
this.setState({
input: event.target.value
})
}
Next. The fCC React curriculum is using React v16.4.0 and because of how React 16 events work (pooling) the event target will be undefined inside the setState updater function.
This is why it crashes when you type into the input Uncaught TypeError: Cannot read property 'value' of null
. One option is to use event.persist()
or save the value at the top of the handler function (only when an updater function is needed).
React 17 does not work like this anymore (No Event Pooling) so it would work (you still shouldn’t use the updater function unless needed).
Examples: