I'm trying to build a nav bar which would search for videos. The idea is extract an array of video titles and filter through to by using user's input from the search bar. The problem is that I cannot get the searchItem to persist. When redirected to /search searchItem is not part of the props. Any suggestions?
import React from "react";
import { Link } from 'react-router-dom';
class SearchBar extends React.Component {
constructor(props) {
super(props);
this.state = {
searchItem: ""
};
this.update = this.update.bind(this);
this.handleSearch = this.handleSearch.bind(this);
}
update() {
return e => this.setState({ searchItem: e.currentTarget.value });
}
handleSearch() {
// debugger
// e.preventDefault();
console.log(this.state.searchItem)
console.log(this.state)
// this.props.location.search = this.searchItem;
}
render() {
return (
<div className="search-form">
<form onSubmit={this.handleSearch()}>
<input type="text"
className="search-input"
placeholder="Search videos"
value={this.state.searchItem}
onChange={this.update()}
/>
<button id="search-button">
<Link to="/search"><img id="search-icon" src="https://image.flaticon.com/icons/svg/49/49116.svg" alt="" /></Link>
</button>
</form>
</div>
);
}
}
export default SearchBar;
class Search extends React.Component {
constructor(props) {
super(props);
console.log(this.props)
}
componentDidMount() {
this.props.fetchVideos();
this.props.fetchUsers();
};