react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Cache options is not working with AsyncSelect

Open yashjais18 opened this issue 5 years ago • 4 comments

I'm trying to use Asyncselect with cache options. What I'm trying to do is when a user gives a input, I want to persist that input as well as the options. I'm loading options via loadOptions prop which is calling an API. But what is happing is when a user selects an option the options are dissapearing. I don't know if its a bug or a feature request but can you guys look into this. Thanks! Here's the sandbox link.

yashjais18 avatar Apr 19 '21 06:04 yashjais18

Hello @yashjais18,

the onInputChange prop has the ability to return the current inputValue. This is mainly used for uncontrolled scenarios. But the Async component uses that returned value to determine if it should reset among other things the loaded options. This reset is triggered by either returning nothing or returning a non-truthy value.

So instead of returning false on selecting the option you should instead return the current value for inputValue.

Rall3n avatar Apr 19 '21 13:04 Rall3n

Hey. I resolved the issue I was having. So we needed to store the data which we're returning from API. And then we needed to give it as default options. So now the dropdown will also persist options. And thanks for the fast reply! Also one more thing. I was returning from function(which is passed ot loadOptions) like this, that's why It wasn't work for me initially:- this.setState({data: response.data}, () => return data); We need to set the state and return data separately, like this:- this.setState({data: response.data}); return data;

yashjais18 avatar Apr 20 '21 06:04 yashjais18

i94furi9efurehfguhrtgv

ankita-th avatar Dec 02 '24 10:12 ankita-th

refgewrgergerfv

ankita-th avatar Dec 02 '24 10:12 ankita-th