Is there a way to useParams() in a class in v6 of react-router-dom?

After many videos and googling I can't really find what I'm looking for as useParams() works but with a function and not a class. Dose anyone know a way to fix this? Here is the version I tried as a class
class ProductDetails extends Component {
handleSave = () => {
console.log("test");
};

render() {
const params = useParams();

return (
<div>
<h1>Product Details - {params.id} </h1>
<button onClick={this.handleSave}>Save</button>
</div>
);
}
}
class ProductDetails extends Component {
handleSave = () => {
console.log("test");
};

render() {
const params = useParams();

return (
<div>
<h1>Product Details - {params.id} </h1>
<button onClick={this.handleSave}>Save</button>
</div>
);
}
}
Here is the version I tried as a funtion
const Details = () => {
handleSave = () => {
console.log("test");
};

const params = useParams();

return (
<div>
<h1>Product Details - {params.id} </h1>
<BtnHandleSave onClick={this.props.onHandleSave()}></BtnHandleSave>
</div>
);
};
const Details = () => {
handleSave = () => {
console.log("test");
};

const params = useParams();

return (
<div>
<h1>Product Details - {params.id} </h1>
<BtnHandleSave onClick={this.props.onHandleSave()}></BtnHandleSave>
</div>
);
};
2 Replies
Daryl
Daryl2y ago
There is any error? How do you expect it to work? Please read this to ask good questions: https://discord.com/channels/436251713830125568/1022288836715356180
kingtigerknight
kingtigerknightOP2y ago
The error is that can't useParams() in a class in v6 of react-router-dom from the title of the post. For how I expect it to work is something similar for a useParams() to work but with a function and not a class in the description of the post.
Want results from more Discord servers?
Add your server