[英]How to change button text in Reactjs for a few seconds?
I know how to change the text of button (using a component state for example).我知道如何更改按钮的文本(例如使用组件 state)。 But how to change the text for a few seconds?
但是如何改变几秒钟的文字呢?
For example: I click button with the text "Save".例如:我单击带有文本“保存”的按钮。 The request goes on the server and when I get response from the server and there are no mistakes, I need to change the text of the button on "Saved" for 3 seconds and return "Save" then.
请求在服务器上进行,当我得到服务器的响应并且没有错误时,我需要将“已保存”按钮的文本更改 3 秒钟,然后返回“保存”。
you can do it like so你可以这样做
handleClick = () => {
this.setState({ text: "Loading..." });
setTimeout(() => {
this.setState({ text: "Save" });
}, 5000);
};
Change the state of button text inside timeout.更改超时内按钮文本的 state。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.