Unhandled Rejection (TypeError): Cannot read properties of undefined (reading ‘params’)


I am getting an error while showcasing single product on screen, the error is stated as-

Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'params')

The code which is causing the error is

function ProductScreen({ match }) {
  const [product, setProduct] = useState({})

  useEffect(() => {
    const fetchProduct = async () => {
      const { data } = await axios.get(`/api/products/${match.params.id}`)

      setProduct(data)
    }

    fetchProduct()
  }, [match])

I guess the error is of match.params.id, But I am having a hard time to resolve the error.Can anyone know the fix to this error?

Source: JavaSript – Stack Overflow

November 30, 2021
Category : News
Tags: javascript | mern

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.