Home > Blockchain >  Is this bad habit in react?
Is this bad habit in react?

Time:01-06

Ive used

const location = useLocation()
const searchParams = new URLSearchParams(location.search)
const productId = searchParams.get('productId')

to get the productId from the params. Is this a bad habit, any downsides? Are there better alternatives?

CodePudding user response:

Assuming it's react-router-dom, you can use it's api:

const params = useParams();

CodePudding user response:

you can use the useParams hook of react :

const params = useParams();

but your code is ok

  • Related