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

Remove any from useAsyncLoader #1282

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

andrewHEguardian
Copy link
Contributor

What does this change?

Trying to refactor to make sure we have no anys in the the useAsyncLoader hook.

How to test

How can we measure success?

Have we considered potential risks?

Images

Accessibility

@@ -39,7 +39,7 @@ export function useAsyncLoader<T>(
asyncFetch()
.then((response) => responseProcessor(response))
.then((data) => {
setData(data);
setData(data as T);
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

@andrewHEguardian andrewHEguardian marked this pull request as ready for review January 19, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants