useParams in TypeScript does not allow destructuring
useParams
is generic. You need to tell typescript which params you are using by specifying the value of the generic like this: useParams<MyParams>()
; In your case it is:
const { token } = useParams<{token?: string}>();
Which says that token
is either a string
or undefined
.
Yep, typescript can't destructure generic plain objects like {}
.But any
works like a charm.
const { token } = useParams() as any