tbleckert / react-select-search

⚡️ Lightweight select component for React
https://react-select-search.com
MIT License
676 stars 147 forks source link

onSearch event #104

Closed mhutfield-Itrinegy closed 4 years ago

mhutfield-Itrinegy commented 4 years ago

is there some event to hook into for when the input box is typed into, the onChange event only seems to fire when you actually select something from the dropdown list. Thanks

etc-tiago commented 4 years ago

You can use getOptions:

<SelectSearch
    options={[]}
    getOptions={(query) => {
        return new Promise((resolve, reject) => {
            fetch(`https://www.thecocktaildb.com/api/json/v1/1/search.php?s=${query}`)
                .then(response => response.json())
                .then(({ drinks }) => {
                    resolve(drinks.map(({ idDrink, strDrink }) => ({ value: idDrink, name: strDrink })))
                })
                .catch(reject);
        });
    }}
    search
    placeholder="Your favorite drink"
/>
mhutfield-Itrinegy commented 4 years ago

Thanks

AlexBasile123 commented 3 years ago

Thanks, was looking for the same question