【发布时间】:2022-09-29 13:11:19
【问题描述】:
当我单击按钮时,如果按钮的值为 0,则文本不会显示在该空间中。我的意思是,不显示-10怎么办?
console.log(variable)
这是我得到的错误..
const Mobile = () => {
const [charge, setCharge] = useState(20)
const setMobileCharge = () => setCharge(charge - 10)
if (setMobileCharge === 0) {
return 0;
}
return (
<div>
<h3>Charge : {charge}</h3>
<button onClick={setMobileCharge}>Battery down</button>
</div>
);
};
导出默认手机;
标签: javascript reactjs react-component