I'm trying to load a new component i have made when i press the button 'Enter'. I have implemented the onKeyPress function successfully as follows.
class SearchBar extends Component {
constructor(props) {
super(props);
this.handleKeyPress = this.handleKeyPress.bind(this);
}
handleKeyPress(e) {
if (e.key === 'Enter') {
console.log("load new page");
}
}
render() {
return (
<div className="search_bar_div">
<div className="search_bar_internal_div">
{/* Search bar for desktop and tablets */}
<span className="Rev_logo">Revegator</span>
<input type="search" placeholder="Search here" className="search_bar"
onKeyPress={this.handleKeyPress}/>
</div>
</div>
}
I get the console log correctly but the problem i have is how to load the component when i press Enter.