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

TypedLink and useTypedRoute #3846

Closed
Zeko369 opened this issue Sep 18, 2022 · 0 comments
Closed

TypedLink and useTypedRoute #3846

Zeko369 opened this issue Sep 18, 2022 · 0 comments
Labels

Comments

@Zeko369
Copy link
Collaborator

Zeko369 commented Sep 18, 2022

What do you want and why?

From @blitzjs/next export 2 new utils

  1. <TypedLink> allowing us to write typesafe links by default
  2. useTypedRoute when called without props it's the same as useRouter but enforces the use of typesafe routes in push/replace, but if called with a prop also types router.query (example below)

Possible implementation(s)

Super simple example of just key + args way of doing it, we could also make it so it's either Routers.Page or This way

const TypedLink = <T extends keyof typeof Routes>({}: { page: T } & Parameters<
  typeof Routes[T]
>[0]) => {
  ...
}

CleanShot 2022-09-18 at 23 43 25@2x

const useTypeSafeRouter = <T extends keyof typeof Routes>(
  page: T
): Omit<NextRouter, "query"> & { query: Parameters<typeof Routes[T]>[0] } => {
  return useRouter()
}

CleanShot 2022-09-18 at 23 42 12@2x

Additional context

This can be done in userland, but if we make it so it has to be done in userland a lot of people will ignore it, this will make it easier to "enforce better practices on people"

@beerose beerose added the status/ready-to-work-on This issue is up for grabs label Sep 19, 2022
@beerose beerose added kind/feature-change New feature or request status/triage labels Sep 19, 2022
@blitzjs-bot blitzjs-bot removed the status/ready-to-work-on This issue is up for grabs label Sep 19, 2022
@beerose beerose added status/ready-to-work-on This issue is up for grabs and removed status/triage labels Sep 19, 2022
@blitzjs-bot blitzjs-bot added status/done and removed status/ready-to-work-on This issue is up for grabs labels Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

4 participants