Skip to content

Instantly share code, notes, and snippets.

@BrightnBubbly
Created August 10, 2018 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrightnBubbly/1274bbeac4b436d593564053f8a52d38 to your computer and use it in GitHub Desktop.
Save BrightnBubbly/1274bbeac4b436d593564053f8a52d38 to your computer and use it in GitHub Desktop.
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