【发布时间】:2021-06-17 17:55:09
【问题描述】:
使用 React Hooks 我想在用户单击按钮时更改按钮的文本以说“已添加”,然后我想在 1 秒后将其设置回原始文本“添加到购物车”。我假设我会为此使用 setTimeout,但在这种情况下无法弄清楚如何使用它。
我有这个
const [buttonText, setButtonText] = useState("Add To Cart");
到目前为止。
<button
type="submit"
onClick={() => setButtonText("Added")}
>
{buttonText}
</button>
【问题讨论】:
标签: html reactjs button react-hooks settimeout