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

[v6] [Feature]: useMatch params aren't type-safe #7978

Closed
ChristianIvicevic opened this issue Aug 30, 2021 · 1 comment
Closed

[v6] [Feature]: useMatch params aren't type-safe #7978

ChristianIvicevic opened this issue Aug 30, 2021 · 1 comment

Comments

@ChristianIvicevic
Copy link

What is the new or updated feature that you are suggesting?

I am interested in having the possibility to declare the parameters used within useMatch such as useMatch(':domain/:id/:category') with a generic version of useMatch to supply something such as this:

type RouteProps = {
  readonly domain: string;
  readonly id: string;
  readonly category: string;
};

const match = useMatch<RouteProps>(':domain/:id/:category');

Why should this feature be included?

The feature helps to refactor usages in expressions such as active={match?.params.category === path} which are otherwised not strictly typed since params is of type Record<string, string> right now. Changing the name of a param in the path pattern is inherently unsafe, however when there is an explicit generic type parameter one might be forced to update the underlying type and automatically refactor all usages.

@chaance chaance changed the title [v6][Feature]: useMatch params aren't type-safe [v6] [Feature]: useMatch params aren't type-safe Sep 4, 2021
@mjackson
Copy link
Member

We added this in v6.0.0-beta.4

See https://github.com/remix-run/react-router/releases/tag/v6.0.0-beta.4

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

No branches or pull requests

2 participants