DEV Community

Hiroshima
Hiroshima

Posted on

Undefined error

const ProductScreen = ({ match }) => {
const [product, setProduct] = useState({})
useEffect(() => {
const fetchProduct = async () => {
const { data } = await axios.get(
/api/products/${match.params.id})
setProduct(data)
}
fetchProduct();
})

I'm using useEffect and axios to get the data from backend but the console keeps on showing me this error

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

Top comments (0)