Last active
July 7, 2018 20:31
-
-
Save jonathanharrell/9f47f080ef9585ea370597dea2431be9 to your computer and use it in GitHub Desktop.
React Autocomplete Component (with render props)
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 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