Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: Cannot read properties of undefined (reading 'useParams')

Good day, I’m having problems with the latest react-router-dom v6, I still learning the new version. Please help.

import React from 'react'

function Bookingscrren({match}) {
  return (
    <div>
        <h1>Booking Page</h1>
        <h1>Room id = {match.useParams.roomid}</h1>

    </div>
  )
}

export default Bookingscrren

Browser Output Error:
enter image description here

Please be kind 🙂 I’m new

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

That’s not the right way of using useParams. All of these functions that begin with use, or react hooks, are just those, functions. That means you call them to get access to their functionality.

import React from 'react'

function Bookingscrren() {
const params = useParams();
  return (
    <div>
        <h1>Booking Page</h1>
        <h1>Room id = {params.roomid}</h1>

    </div>
  )
}

The return value of useParams is an object with parameters. You can access each one with the . operator.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading