Skip to content

Instantly share code, notes, and snippets.

@dreadjr
Forked from ajl100b/app.js
Created May 3, 2018 22:34
Show Gist options
  • Save dreadjr/8e1ac637611674897c880cac2bd9de49 to your computer and use it in GitHub Desktop.
Save dreadjr/8e1ac637611674897c880cac2bd9de49 to your computer and use it in GitHub Desktop.
Redirect to search results component upon submit of search terms from search bar embedded in a global navbar
import React, { Component } from 'react'
import { Redirect } from 'react-router'
export default class Search extends Component {
constructor () {
super();
this.state = {
fireRedirect: false
}
}
componentWillRecieveProps(nextProps) {
this.setState({ fireRedirect: false })
}
submitForm = (e) => {
e.preventDefault()
this.setState({ fireRedirect: true })
}
render () {
const { fireRedirect } = this.state
return (
<div>
<form onSubmit={this.submitForm}>
<button type="submit">Submit</button>
</form>
{fireRedirect && (
<Redirect to='/search-results'/>
)}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment