-
Notifications
You must be signed in to change notification settings - Fork 91
Handle unmounting whilst request is in flight #96
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
Conversation
|
|
||
| const fetchDataPromise = fetchData() | ||
| unmount() | ||
| await fetchDataPromise |
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.
nice
bmullan91
left a comment
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.
👍
|
|
||
| const fetchDataPromise = fetchData() | ||
| unmount() | ||
| await fetchDataPromise |
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.
In this test it should resolve the result, right? We can then add a test that after unmount it resolves undefined:
const fetchDataPromise = fetchData()
unmount()
const firstResult = await fetchDataPromise // <- expected actual result
const secondResult = await fetchData() // <- expected undefinedThere 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've added a test for that 👍
Prevents `fetchData` within `useClientRequest` from updating state when a request returns, if the component has unmounted. closes #54 - [x] I have checked the [contributing document](../blob/master/CONTRIBUTING.md) - [x] I have added or updated any relevant documentation - [x] I have added or updated any relevant tests
What does this PR do?
Prevents
fetchDatawithinuseClientRequestfrom updating state when a request returns, if the component has unmounted.Related issues
closes #54
Checklist