实现一个自定义弹出框,在单击React Component中的按钮5秒后显示

时间:2018-03-15 18:04:55

标签: javascript reactjs jsx

我认为标题是自我解释的,我在React组件中有一个按钮元素,我想点击它,它必须在5秒后弹出一个框

import React, { Component } from 'react';
import './Header.css';

class Header extends Component {
  render() {
    return (
      <div>
        <a class="waves-effect waves-light btn">This is the button !</a>
      </div>
    );
  }
}

export default Header; 

1 个答案:

答案 0 :(得分:0)

我认为这应该有用

import React, { Component } from 'react';
import './Header.css';

class Header extends Component {

popupBox(){
setTimeout(()=> alert("hello"),5000)
}
  render() {
    return (
      <div>
        <a class="waves-effect waves-light btn" onClick={()=>this.popupBox()}> This is the button !</a>
      </div>
    );
  }
}