'Rewriting code with useParams, deconstructuring not going well
Trying to upgrade react router to version 5.1.
I have a problem with the useParams, the exampleId is not correct. I'm definatelly missing something?
My Route file with the broken exampleId:
export default function MyExample() {
const { url } = useRouteMatch()
const history = useHistory()
const exampleCreateQuery = useExampleCreate()
return (
<>
<Header url={url} />
<Switch>
<Route path={url} exact>
</Route>
<Route path={`${url}/:id`} children={exampleId !== undefined ? <ExampleThing exampleId={exampleId} /> : null} />
</Switch>
</>
)
}
The route where the id comes from
export default function ExampleThing() {
const { id: exampleId } = useParams<{ id: string }>()
const exampleQuery = useExample(exampleId, { useErrorBoundary: false })
return (
<>
</>
)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
