Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to clear cache result with ASYNC #2582

Closed
shorif2000 opened this issue May 2, 2018 · 7 comments
Closed

how to clear cache result with ASYNC #2582

shorif2000 opened this issue May 2, 2018 · 7 comments

Comments

@shorif2000
Copy link

shorif2000 commented May 2, 2018

i have the following

<Async 
  autoload={false}
  multi={false} 
  value={this.state.selectValue} 
  onChange={this.updateValue} 
  valueKey="value" 
  labelKey="label" 
  loadOptions={this.getCommsmatrices} 
  onValueClick={this.gotoCommsmatrix}
  cache={false}
/>

getCommsmatrices (input, callback) {
  input = input.toLowerCase(); 
  let options = this.state.options.filter(i => {
  	return i.label.toLowerCase().includes(input) == true;
  });

  let data = {
  	options: options,
  	complete: true 
  };

  setTimeout(function() {
  	callback(null, data);
  }, ASYNC_DELAY);
}

once my results are loaded it stays cached. i want to trigger this cache clean externally. how can this be done?

i want to clear the cache in the following function. I have tried setting isLoading but it does not work.

updateCommsMatrix(service_id){
  this.setState({ isLoading: true });
  this.updateValue(null);

  if(service_id > 0){
    let self = this;
  	this.props.fetchCommsmatricesByService(service_id)
      .then( response => {
        let data = response.payload.data.body.recordset.record;
        let options = self.populateOptionsObject(data, 'id', 'filename');
        options.unshift({ value: '0', label: 'All' });
        return options;
      })
      .then( options => self.setState({options:options,isLoading: false}));
  } else {
    this.setState({ options:{ value: '0', label: 'All'},isLoading: false });
  }

  this.props.dispatch(change('SecurityExemptionsNewForm', 'service_id', service_id));
}
@shorif2000 shorif2000 changed the title how to clear cache result how to clear cache result with ASYNC May 2, 2018
@pedalpete
Copy link

I'm also struggling with the @shorif2000 -

I'm trying am trying to create a filter list where if the user has typed more than 3 letters, but no results are returned, we show them the full list of options.

I believe the problem is not in cache but rather that the callback is always returning the filtered result

options: cache[inputValue]

Looking here, my reading is that the cache is always being used and I'm picturing the cache as an object, which holds the keys of everything which has been entered. I haven't tracked down where the options creates the list of results yet.

I thought I'd post here and see if you've had any luck or maybe we can help each other out.

@JedWatson
Copy link
Owner

@shorif2000 @pedalpete could you specify which version of react-select you are using?

@pedalpete
Copy link

I'm on 1.2.1

@shorif2000
Copy link
Author

@JedWatson im on 1.2.1

@jossmac
Copy link
Collaborator

jossmac commented Jul 5, 2018

Possibly related to #2661

@mforman1
Copy link

mforman1 commented Jan 9, 2019

@JedWatson I'm using v2, please advise on how to clear the cache on this version. Thanks!

@bladey
Copy link
Contributor

bladey commented May 28, 2020

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our efforts towards the current major version.

If you aren't using the latest version of react-select please consider upgrading to see if it resolves any issues you're having.

However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you!

@bladey bladey closed this as completed May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants