Skip to content

Instantly share code, notes, and snippets.

@ryanbelke
Created October 21, 2018 01:27
Show Gist options
  • Save ryanbelke/5706a9ed490cb05f973646c820ec6134 to your computer and use it in GitHub Desktop.
Save ryanbelke/5706a9ed490cb05f973646c820ec6134 to your computer and use it in GitHub Desktop.
index.js file for using defaultPage.js
/* /pages/index.js */
import RestaurantList from "../components/RestaurantList";
import React from "react";
import defaultPage from "../hocs/defaultPage";
import {
Alert,
Button,
Col,
Input,
InputGroup,
InputGroupAddon,
Row
} from "reactstrap";
class Index extends React.Component {
constructor(props) {
super(props);
//query state will be passed to RestaurantList for the filter query
this.state = {
query: ""
};
}
onChange(e) {
//set the state = to the input typed in the search Input Component
//this.state.query gets passed into RestaurantList to filter the results
this.setState({ query: e.target.value.toLowerCase() });
}
render() {
return (
<div className="container-fluid">
<Row>
<Col>
<div className="search">
<InputGroup>
<InputGroupAddon addonType="append"> Search </InputGroupAddon>
<Input onChange={this.onChange.bind(this)} />
</InputGroup>
</div>
<RestaurantList search={this.state.query} />
</Col>
</Row>
<style jsx>
{`
.search {
margin: 20px;
width: 500px;
}
`}
</style>
</div>
);
}
}
export default defaultPage(Index);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment