I'd like to get the value from input but I still gets 'Cannot read property 'target' of undefined' and I have no idea why it doesn't work. If someone could explain I'd be thankful
import React from "react";
class Search extends React.Component {
constructor(display) {
super(display);
this.state = {
searchingText: ""
};
}
handleChange(event) {
let searchingText = event.target.value;
this.setState({
searchingText: searchingText
});
if (searchingText.length > 2) {
this.props.onSearch(searchingText);
}
}
handleKeyUp(event) {
if (event.keyCode === 13) {
this.props.onSearch(this.state.searchingText);
}
}
render() {
const styles = {
fontSize: "1.5em",
width: "90%",
maxWidth: "350px"
};
return (
<input
type="text"
onKeyUp={this.handleKeyUp}
onChange={() => this.handleChange()}
placeholder="Tutaj wpisz fraze"
style={styles}
value={this.state.searchTerm}
/>
);
}
}
export default Search;re