refactor: replace custom useLoading hook with ahooks useRequest#2953
Draft
refactor: replace custom useLoading hook with ahooks useRequest#2953
useLoading hook with ahooks useRequest#2953Conversation
useLoading hook with ahooks useRequest across client componentsuseLoading hook with ahooks useRequest
c713d7c to
37073dd
Compare
Contributor
AlreadyBored
left a comment
There was a problem hiding this comment.
useLoading swallowed errors — callers never saw exceptions, just got undefined back. runAsync re-throws after onError, so any call site without try/catch will now produce an unhandled promise rejection. Is that what we want?
| }, | ||
| ); | ||
|
|
||
| const handleDeleteConsent = withLoading(async () => { |
Contributor
There was a problem hiding this comment.
These two funcs lost their withLoading wrapping entirely. No loading state, no error handling, is it okay?
| const { loading: loadingCancelMentor, runAsync: cancelMentor } = useRequest( | ||
| async (githubId: string) => { | ||
| setModalData(null); | ||
| await mentorRegistryService.cancelMentorRegistry(githubId); |
Contributor
There was a problem hiding this comment.
No onError here — if the request fails, the user gets no feedback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
ahooksuseRequestfor clearer semantics and built-in error/side-effect handling.Description
client/src/components/useLoading.tsxand replaced its usage withuseRequestfromahooksacross multiple modules.const [loading, withLoading] = useLoading()call sites intoconst { loading, runAsync: fn } = useRequest(..., { manual: true })or aggregated multipleuseRequestloadings into a combinedloadingflag where appropriate.onErrorhandlers to severaluseRequestcalls to surface user-facing messages viamessage.errorand preserved previous error-handling behavior in most places.Mentor,Teams,Students,Interviews,Notifications,Opportunities,MentorRegistry,AutoTest,StudentDashboard, and others) to call the newrunAsyncfunctions and to useuseRequestfor manual triggers and refresh dependencies.