react-router / useParams

useParams, how do you React?

My adventures in React-Router

Photo by Nubelson Fernandes on Unsplash

How it works

import {
BrowserRouter as Router,
Switch,
Route,
useParams
} from "react-router-dom";
function DisplayImage() {
let { id } = useParams();
return <div>Now showing image {id}</div>
<Router>
<Switch>
<Route exact path="/">
<HomePage />
</Route>
<Route path="/images/:id">
<DisplayImage />
</Route>
<Switch>
</Router>

Handling errors

How I handled my error, by throwing it to another place

The TL/DR

Former tech banker, now aspiring software engineer. Feel free to get in touch.