tbleckert / react-select-search

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

additional steps in onChange #249

Open avianheit07 opened 1 year ago

avianheit07 commented 1 year ago
const [selected, setSelected] = useState('');
<SelectSearch
    options={[]}
    value={selected}
    onChange={setSelected}
    getOptions={(query) => {
        return new Promise((resolve, reject) => {
            HTTP_API().get(url)
                .then((response) => {
                    if (response.status === 200) {
                      resolve(response.data.map(({ id, name }) => ({
                            value: id,
                            name: name
                      })));
                    }
                  })
                  .catch(reject);
            });
          }}
    search
    placeholder="To: "
/>

how to add additional steps on onChange and retain its original behaviour? I tried the above code but every time I select an item it closes the dropdown and does not show the selected option. this is my current version 4.1.2

If I omit the value and onChange properties, the value displays for the selected option but I cannot get and use the value of the selected option.