This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
feat: Added helping generic types for hooks #3726
Open
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.
When using TypeScript and code generation tools for GraphQL query typings, the use of hooks such as
useQuery
can become very bloated with long generics, and what should probably a simple one liner gets quite hard to read, specially with multiple hooks (many mutations, for instance).No TypeScript:
Typescript:
What this pull-request does is export a generic type to allow typing of queries/mutations before we use hooks. Outcome could be something like this:
TypeScript with UseQuery/UseMutation/UseSubscription:
As can be seen, this makes it easier to reduce complexity and code within the component itself, while moving static non-variable procedures such as typing outside the business code.