React Async Select

David Casanellas picture David Casanellas · Nov 20, 2018 · Viewed 10.6k times · Source

I am struggling with Async Select from react-select. I managed to display some defaultOptions and do an async fetch of its options using promises and loadOptions prop.

What I need is to have the options updated (resolve the promise) when the dropdown of options is displayed on click. Is there a way to execute the same promise onClick (even in onChange)?

I am using the following codepen provided by react-select team https://codesandbox.io/s/7w4w9yyrmx?module=/example.js

Thank you for your help!

Answer

David Casanellas picture David Casanellas · Nov 21, 2018

I actually found a way to solve it using a basic react-select. I am going to manage the options using a react state being set onMenuOpen. Using this approach, I have control on what options are displayed when the user clicks on the select.

https://codesandbox.io/s/vnmvrwoj63