'UpdateProduct.js:56 Uncaught TypeError: Cannot read properties of undefined (reading 'params')

hey i am making an update a product in my react so i am preloading all my existing product data into the my updation form so that we can make some changes in it but i am getting error

This is where issue is causing ===>

    const preload = productId => {
        getProduct(productId).then((data) => {
          if (data && data?.error) {
              
            setValues({ ...values, error: data?.error });
          } else {
            setValues({
              ...values,
              name: data.name,
              description: data.description,
              price: data.price,
              stock: data.stock,
              category: data.category._id,
              formData: new FormData(),
            });
          }
        });
      };

    useEffect(() => {
preload(match.params.productId);
    }, [])


Solution 1:[1]

You should have a look at 'match' value in the code below. It seems its value is not what you think.

useEffect(() => {
    preload(match.params.productId);
    }, [])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fred