0

this is my code and it shows "Cannot read properties of undefined (reading 'params') TypeError: Cannot read properties of undefined (reading 'params')" I don't know what to do and I am a beginner to MERN. i will hope anyone will help me

`import React ,{useState,useEffect}from 'react' import DefaultLayout from '../components/DefaultLayout' import { useSelector, useDispatch } from 'react-redux' import { getAllCars } from '../redux/actions/carsAction'

function BookingCar({match}) {
  const {cars }=useSelector(state=>state.carReducer)
  const {loading}=useSelector(state=>state.alertsReducer)
  const[car,setcar]=useState({})
  const dispatch=useDispatch()

  useEffect(()=>{
   dispatch(getAllCars())
    if(cars.length>0){
      setcar(cars.find(o=>o._id==match.params.carid))
    }
  },[cars])
  return (
    <DefaultLayout>
        <h1>BookingVehicle page</h1>
        <h1>car Name ={car.name}</h1>
    
    </DefaultLayout>
  )
}

export default BookingCar`

i try to add "import { useParams } from 'react-router-dom'; " but idon't know how to do it

0 Answers0