const submitHandler = (event:FormEvent<HTMLFormElement>) => {
event.preventDefault();
let type = 'product/ProductAdd';
let payload = {
id:nanoid(),
name:inputValue.name,
price:inputValue.price,
};
if (inputValue.id) {
type = 'product/ProductEdit';
payload.id = inputValue.id;
}
dispatch({type, payload})
setInputValue(initialState);
setCancel(false);
}
...
const onClickEdit = (id: string) => {
const selectedProduct = product.find((elem: { id: string }) => elem.id === id);
setInputValue({
id:selectedProduct.id,
name:selectedProduct.name,
price:selectedProduct.price,
});
setCancel(true);
}