我正在尝试使用名为 onIncrement 的 onClick 来增加产品的数量。功能如下:
const onIncrement = () => {
setState({ ...state, quantity: (state.quantity) + 1 });
props.productList(props.productData.price*(state.quantity + 1))
};
我希望按钮在每次单击按钮时简单地向产品添加 +1。不幸的是,每次单击按钮时,此功能都会使数量增加一倍。有没有简单的方法来解决这个问题?我试着做:
const onIncrement = () => {
setState({ ...state, quantity: (state.quantity)/(state.quantity) + 1 });
props.productList(props.productData.price*(state.quantity + 1))
};
否定 state.quantity 的影响,只添加一个,但它不起作用。我在公式中遗漏了什么吗?谢谢