Created
August 10, 2018 20:32
-
-
Save BrightnBubbly/1274bbeac4b436d593564053f8a52d38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
class Search extends Component { | |
static props = { | |
onSubmit: PropTypes.func.isRequired, | |
}; | |
constructor(props) { | |
super(props); | |
this.state = { | |
query: '', | |
}; | |
this.stateChange = this.stateChange.bind(this); | |
this.fetch = this.fetch.bind(this); | |
} | |
stateChange(event) { | |
this.setState({ query: event.target.value }); | |
} | |
fetch(event) { | |
event.preventDefault(); | |
this.props.onSubmit({ query: this.state.query }); | |
} | |
render() { | |
return ( | |
<div> | |
<input | |
className="input" | |
name="query" | |
placeholder="Search..." | |
onChange={this.stateChange} | |
/> | |
<button onClick={this.fetch} type="submit"> | |
Fetch | |
</button> | |
</div> | |
); | |
} | |
} | |
export default Search; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment