I am trying to populate the state after calling an action which retrieves the data of an single object. I want to store this data in the state directly.
useEffect(() => {
getProduct(id);
}, [getProduct]);
const [formData, setFormData] = useState({});
I tried to store like this:
const ProductEdit = ({getProduct, updateProduct, id, products}) => {
useEffect(() => {
getProduct(id);
}, [getProduct]);
const [formData, setFormData] = useState({
name: '',
quantity: '',
price: '',
description: '',
category: '',
isImportant: ''
});
const {name, quantity, price, description} = formData;
products.product && setFormData(products.product);