user3378165
user3378165

Reputation: 6896

Clear cached options on async select

I have an Async react-select (v2) that changes its loadOptions based on tabs change. The issue is that when switching tabs the select is still showing the results of the previous api call that were cached. The cache needs to be purged every time the tabs change.

 <Async
    cacheOptions
    isClearable
    loadOptions={props.loadOptions}
    {...this.selectProps(inputText, props)}
  />

I have seen in a few places that the React-Select v2 will include the option to reset the cache for the Async select, but I couldn't find in the documentation an example on how to do it.

Please advise.

Upvotes: 6

Views: 6689

Answers (1)

user3378165
user3378165

Reputation: 6896

With an hack, by adding a key with some changing prop to the async select- I was able to get the results cleared on tab click:

 key={this.state.searchBy}

Upvotes: 14

Related Questions