I want to activate the delete button in the table using its id. It's a crud app, I wrote this code for "Edit" and "Add" operations, and I wrote this code for deleting a row(product). But I am getting an error: "Expected an assignment or function call and instead saw an expression no-unused-expressions". Where do I have a mistake? Have I written the onClick event correctly?
const Products = () => {
const[products, setProducts] = useState([]);
useEffect(() => {
loadProducts();
},[]);
const loadProducts = async () => {
const result = await axios.get("http://localhost:3001/products");
setProducts(result.data);
};
const deleteUSer = async id => {
await axios.delete(`http://localhost:3001/products/${id}`);
loadProducts();
}
<Link className='btn btn-otline-primary m-2' to={`/product/edit/${product.id}`}>Edit</Link>
<Link className='btn btn-danger m-2' onClick={()=>{deleteUSer}}>Delete</Link>
CodePudding user response:
You are miss-calling your deleteUser
It should either be called explicitly like:
<Link className='btn btn-danger m-2' onClick={()=>{deleteUSer()}}>Delete</Link>
Or implicitly like:
<Link className='btn btn-danger m-2' onClick={deleteUSer}>Delete</Link>