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

Return a promise from forceRequest? #81

Closed
soulostar opened this issue Jun 20, 2017 · 3 comments
Closed

Return a promise from forceRequest? #81

soulostar opened this issue Jun 20, 2017 · 3 comments

Comments

@soulostar
Copy link

soulostar commented Jun 20, 2017

Currently forceRequest has no return value, but I think it would be useful if it returned a promise (could handle fulfillment/rejection similarly to Promise.all, but the actual fulfillment/rejection values are not too important for the use case I have).

Use case: I'm using redux-query with a React Native project, and I have a component that is connectRequested with one query. I want to implement refresh functionality via https://facebook.github.io/react-native/docs/refreshcontrol.html, which takes a refreshing prop to determine if it should show the spinner above the top of the view. I can't just use the result of isPending for the query as the value for refreshing, because then the spinner will show when the component first mounts and performs the initial data fetch (and the rest of the view gets pushed down to make room for the spinner for no reason). I want to do something like:

handleRefresh = () => {
  this.setState({ isRefreshing: true });
  this.props.forceRequest().finally(() => {
    this.setState({ isRefreshing: false });
  });
}

I do have a workaround, which is manually wiring up the request I want to make on refresh via mapDispatchToProps and calling that instead of forceRequest, but that makes me do a lot of the work that connectRequest is supposed to save me from doing, so I was wondering if it'd be useful for forceRequest to return a promise.

@ryanashcraft
Copy link
Contributor

@soulostar Makes sense to me. Perhaps an array of promises since you can make multiple requests with connectRequest and forceRequest currently re-triggers all of them? You'd be able to use Promise.all to handle the case when all have completed.

I'd accept a PR with this change if you're interested in making one!

@karevn
Copy link
Contributor

karevn commented Sep 6, 2018

I implemented it here: #105

@ryanashcraft
Copy link
Contributor

We decided not to change the API for forceRequest. We are moving forward with a new hooks API (see #129 for the PR) that should help with this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants