React v5 to v6 update help with params update

Hello, dose anyone know a way to update v5 this.props.match.params.id into v6 which is import { useParams } from "react-router-dom"; but with out changing the class into a function? I tried to search for a way however I can't seem to find a solution for this. Here is one of my code that needs to be updated
componentDidMount() {
const genres = getGenres();
this.setState({ genres });

const movieId = this.props.match.params.id;
if (movieId === "new") return;

const movie = getMovie(movieId);
if (!movie) return this.props.history.replace("/not-found");

this.setState({ data: this.mapToViewModel(movie) });
}
componentDidMount() {
const genres = getGenres();
this.setState({ genres });

const movieId = this.props.match.params.id;
if (movieId === "new") return;

const movie = getMovie(movieId);
if (!movie) return this.props.history.replace("/not-found");

this.setState({ data: this.mapToViewModel(movie) });
}
Here you can see that in const movieId = this.props.match.params.id; it has the this.props.match.params.id however that doesn't work anymore in v6. It's in a class however I would like to keep it as a class and not changed it into a function if possible. Dose anyone know a way?
class Form extends Component
class Form extends Component
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server