I'm trying to set up my search so when I click enter it will begin to search and redirect to the search page. I was looking through the documentation and it wasn't clear how to set this up. How can I set up pressing enter to begin the search? I'm having a tough time figuring this out, even though I think it should be simple.
class SearchBar extends Component { constructor(props) { super(props) this.state = {query: '', results: [], isLoading: false} } componentWillMount() { this.resetComponent() } resetComponent = () => this.setState({ isLoading: false, results: [], value: '' }) search(query) { this.setState({ query }); axios .get(`/api/search?query=${query}`) .then(response => { console.log(query); this.setState({ results: response.data}); }) .catch(error => console.log(error)); } handleSearchChange = (query) => { this.search(query); this.setState({ isLoading: true, query }) setTimeout(() => this.setState({ isLoading: false, }) , 300) } handleResultSelect = (e, { result }) => this.setState({ query: result} ) render () { const resultRenderer = ({ title }) => <List content = {title}/> return ( <Search loading={this.state.isLoading} onResultSelect={this.handleResultSelect} onSearchChange={(event) => {this.handleSearchChange(event.target.value)}} showNoResults={false} query={this.props.query} selectFirstResult = {true} resultRenderer={resultRenderer} results ={this.state.results} { ...this.props} /> ); } } export default SearchBar Thanks!
onKeyPressprop handler (and checking if it's the enter key) not work? If so, what errors for you get. That's what I did with my react semantic UI form