-
Notifications
You must be signed in to change notification settings - Fork 65
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
Use requests PR #159
Use requests PR #159
Conversation
@mili-confluent, do you have any thoughts on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this is amazing! Should help with some important use-cases.
); | ||
|
||
requestQueryConfigs.forEach(dispatchRequestToRedux); | ||
cancelKeys.forEach(queryKey => dispatchCancelToRedux(queryKey)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a little concern here. Because I also wrote my own useRequests
for my company. One edge case is if we first mount a component which has requests [A, B, C] and then we immediately unmount this component so that [A,B,C] will be cancelled (Assume [A,B,C] are all pending before unmounting). If you re-mount that component (for example, reopen that page), it will not request any [A,B,C] as they are already got cancelled. I am not sure whether this code will solve this problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, I saw in useRequest
we did some transform on queryConfig,
{retry: true}
To solve this problem, maybe we also need to do this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I am currently setting {retry: true}
in the use-memoized-query-configs.js
. So the retry logic is there. This should be moved out and passed into the memoize function. It still has the {retry: true}
, but the memoize should be agnostic to this, like how the current use-request.js
works. I will change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's okay, as long as we add {retry: true}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version in someplace is 3.3.0-alpha.7
and someplace is 3.3.0-alpha.6
, is that okay? Otherwise, LGTM, thank you.
Description
useRequests
is a react hook that takes in an array of query configs and returns two values. The first is an object containing valuesisFinished
andisPending
.isPending
is true as long as any of the network calls made byuseRequests
is still in progress.isFinished
is false as long all requests have not finished. The other value returned is a refresh function. This function when called forces all requests to be recalled no matter the response or status of the previous call.Upgrade
This is meant to be a replacement to the v2 mapPropsToConfig functionality. Redux Query React did not have a good way of making batch requests in v3.
Architecture
This PR mostly copies both the current
useRequest
and v2connect-request
to make a hook for an array of query configs.Feature Request
#158