In react-router
v6 the match.params
has been removed, with only the useParams()
hook available. Now I can't figure out the tweak. The code below is made on Router v4. How can I make the indicated code work using useParams()
. Can't figure it out:
import React, { Component } from "react";
import Palette from "./Palette";
import Seeds from "./Seeds";
import { makePalette } from "./ColorHelpers.js";
import { Route, Routes, useParams } from "react-router-dom";
export default class App extends Component {
findPalette(id) {
return Seeds.find(function (palette) {
return palette.id === id;
});
}
routeProps() {
let id = useParams()
}
render() {
return (
<Routes>
<Route exact path="/" element={<h1>PALETTE LIST GOES HERE</h1>} />
<Route
exact
path="/palette/:id"
render={routeProps => ( // <-- this code
<Palette
palette={makePalette(
this.findPalette(routeProps.match.params.id)
)}
/>
)}
/>
</Routes>
);
}
}
I have tried changing the render
to element
and removing the arrow function routeProps => ()
into a separate function with useParams()
.