Skip to content

Instantly share code, notes, and snippets.

@jonathanharrell
Last active July 7, 2018 20:31
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 jonathanharrell/9f47f080ef9585ea370597dea2431be9 to your computer and use it in GitHub Desktop.
Save jonathanharrell/9f47f080ef9585ea370597dea2431be9 to your computer and use it in GitHub Desktop.
React Autocomplete Component (with render props)
import SearchSelect from './search-select'
class Autocomplete extends React.Component {
constructor(props) {
super(props)
}
filterMethod (options, query) {
return options.filter(option => option.toLowerCase().includes(query.toLowerCase()))
}
render() {
return (
<SearchSelect
options={this.props.options}
filterMethod={this.filterMethod}
render={({results, searchList}) => (
<div>
<input
type="text"
placeholder="Type to search list"
onChange={searchList}
/>
<ul>
{results.map(option => (
<li>{option}</li>
))}
</ul>
</div>
)}
/>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment