Skip to content

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

@ChristianIvicevic

Description

@ChristianIvicevic

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions