Skip to content

Instantly share code, notes, and snippets.

@pnispel
Created December 20, 2017 23:06
Show Gist options
  • Save pnispel/1c45ae1d656e47b1b47d455a9a297ae0 to your computer and use it in GitHub Desktop.
Save pnispel/1c45ae1d656e47b1b47d455a9a297ae0 to your computer and use it in GitHub Desktop.
Filter
class Filter {
render() {
const { onChange, options } = this.props
return (
<select onChange={onChange}>
{options.map((option) => <option value={option.value}>{option.label}</option>)}
</select>
)
}
}
class Parent {
onFilterUpdate(e) {
const filter = e.target.value /* new_arrivals | best_sellers */
api.getResultsWithFilter({ filter })
}
render() {
const filterOptions = [
{value: 'new_arrivals', label: 'new arrivals'},
{value: 'best_sellers', label: 'best sellers'},
]
return (
<Filter onChange={this.onFilterUpdate.bind(this)} options={filterOptions} />
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment