Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在reactJS中设置警报的时间间隔/超时?_Javascript_Reactjs - Fatal编程技术网

Javascript 如何在reactJS中设置警报的时间间隔/超时?

Javascript 如何在reactJS中设置警报的时间间隔/超时?,javascript,reactjs,Javascript,Reactjs,我有一个关于onclick事件的警报。但我希望警报持续两秒钟,并在2秒钟后自动关闭。如何在reactJS中设置警报的时间 const handleHide1 = () => this.setState({ show1: false }); const handleShow1 = () => this.setState({ show1: true }); return( <div> <Alert show={this.state.show1} variant="s

我有一个关于onclick事件的警报。但我希望警报持续两秒钟,并在2秒钟后自动关闭。如何在reactJS中设置警报的时间


const handleHide1 = () => this.setState({ show1: false });
const handleShow1 = () => this.setState({ show1: true });

return(
<div>
<Alert show={this.state.show1} variant="success" style={{marginTop:'2%'}} onHide={this.handleHide1} >
<Alert.Heading closeButton>Order Accepted
<button type="button" class="close" onClick={handleHide1} aria-label="Close">
<span aria-hidden="true">&times;</span></button>
</Alert.Heading>                  
<p>Thank you for Accepting Order. We will inform the customer</p>
</Alert>

<Button variant="outline-success" onClick={()=>{handleShow1}>Accept</Button>

const handleHide1=()=>this.setState({show1:false});
const handleShow1=()=>this.setState({show1:true});
返回(
接受订单
&时代;
感谢您接受订单,我们会通知客户的

{handleShow1}>接受
像这样的东西

const handleShow1 = () => {
  this.setState({
     show1: true
  })

  setTimeout(() => {
     this.setState({
         show1: false
     })
  }, 2000)
}

此外,我还为您制作了一个沙盒,让您了解它: 像这样的事情

const handleShow1 = () => {
  this.setState({
     show1: true
  })

  setTimeout(() => {
     this.setState({
         show1: false
     })
  }, 2000)
}

此外,我还为您制作了一个沙盒,让您了解它:

Hi@madhav koirala,我刚刚为您提供了答案。如果您有任何问题,请告诉我。Hi@madhav koirala,我刚刚为您提供了答案。如果您有任何问题,请告诉我。