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

[Bug]: Generic of hook useParams require string type #8347

Closed
TbIKoBKa opened this issue Nov 17, 2021 · 2 comments
Closed

[Bug]: Generic of hook useParams require string type #8347

TbIKoBKa opened this issue Nov 17, 2021 · 2 comments
Labels

Comments

@TbIKoBKa
Copy link

What version of React Router are you using?

6.0.2

Steps to Reproduce

  1. Add route with dynamic params
  2. Create page component as prop element to route from step 1
  3. Import useParams from react-router to module with page
  4. Call useParams with generic type object to get a few params

Expected Behavior

Destruct return object from useParams

Actual Behavior

Got an error
image
because of generic type
image

@TbIKoBKa TbIKoBKa added the bug label Nov 17, 2021
@kresli
Copy link

kresli commented Nov 17, 2021

I believe this is not a bug.
you need to use it as

const {id} = useParams<"id">()

in a case of multiple params

const {name, age} = useParams<"id" |"age">();

@TbIKoBKa
Copy link
Author

@kresli Thanks! It works. I am used to use an object generic and thought, that is a bug.

brophdawg11 pushed a commit that referenced this issue Mar 27, 2024
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants