-
Notifications
You must be signed in to change notification settings - Fork 4
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
Remove any
from useAsyncLoader
#1282
base: main
Are you sure you want to change the base?
Conversation
@@ -39,7 +39,7 @@ export function useAsyncLoader<T>( | |||
asyncFetch() | |||
.then((response) => responseProcessor(response)) | |||
.then((data) => { | |||
setData(data); | |||
setData(data as T); |
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 basically the crux of the refactor - using as
to assert it's the type, since we're not parsing it at all
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.
Would it make sense to add some validation here before casting to T
? Is there a pattern for doing that in this codebase already? We use zod in some other projects.
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.
yes, absolutely. Seemed like a step too far for this PR - but I think zod was just added to the codebase recently
What does this change?
Trying to refactor to make sure we have no
any
s in the theuseAsyncLoader
hook.How to test
How can we measure success?
Have we considered potential risks?
Images
Accessibility