Javascript 如何在x毫秒后隐藏工具提示

Javascript 如何在x毫秒后隐藏工具提示,javascript,reactjs,ecmascript-6,react-bootstrap,Javascript,Reactjs,Ecmascript 6,React Bootstrap,试图弄明白如何在x秒后隐藏工具提示 在覆盖图中显示后: 我正在和一个朋友一起使用 导出类用户列表扩展组件{ render(){ 常数{ handleResetPassword, 重置电子邮件验证状态, resetEmailValidationUser, 状态颜色, 状态消息, 使用者 }=这是道具 const userList=users&&users.map( (用户)=> ) 返回( uuid 弗斯特 最后 电子邮件 {userList} ) } } 导出类用户扩展组件{ 构造函数(){ 超

试图弄明白如何在x秒后隐藏工具提示 在覆盖图中显示后:

我正在和一个朋友一起使用

导出类用户列表扩展组件{
render(){
常数{
handleResetPassword,
重置电子邮件验证状态,
resetEmailValidationUser,
状态颜色,
状态消息,
使用者
}=这是道具
const userList=users&&users.map(
(用户)=>
)
返回(
uuid
弗斯特
最后
电子邮件
{userList}
)
}
}
导出类用户扩展组件{
构造函数(){
超级()
此.state={
显示工具提示:false
}
this.buttonEl=未定义
}
组件将接收道具(下一步){
常量{resetEmailValidationUser,resetEmailValidationState}=nextProps,
{uuid}=nextrops.user
this.setState({showTooltip:uuid==resetEmailValidationUser&&resetEmailValidationState===success'})
}
componentDidMount(){
if(this.overlay.show){
//this.overlay.show=false
ReactDOM.findDOMNode(this.overlay).show=false
}
}
render(){
常数{
handleResetPassword,
重置电子邮件验证状态,
resetEmailValidationUser,
状态颜色,
statusMessage}=this.props,
{uuid,firstName,lastName,email}=this.props.user,
按钮=(
this.buttonEl=el}>
this.overlay=el}
target={()=>ReactDOM.findDOMNode(this.refs.target)}
>
{statusMessage}
handleResetPassword(uuid,电子邮件)}
ref=“目标”
>
重置密码
)
返回(
{uuid}
{firstName}
{lastName}
{email}
{按钮}
)
}
}

我不太明白如何触发隐藏(将show设置为false,但何时何地?

我想您可以收听Overlay
onenterned
并触发setState将show设置为false。比如:

export class User extends Component {
  constructor(){
    super()
    this.state {
      showTooltip: true
    }
    this.buttonEl = undefined
  }

  hideTooltip(){
     setTimeout(() => this.setState({ showTooltip: false }), 3000)
  }

  render() {
    console.log(this)
    const {
        handleResetPassword,
        resetEmailValidationState,
        resetEmailValidationUser,
        statusColor,
        statusMessage } = this.props,
      { uuid, firstName, lastName, email } = this.props.user,
      overlayProps = { show: uuid === resetEmailValidationUser},
      button = (
        <span ref={(el) => this.buttonEl = el}>
          <Overlay
            animation
            delayHide="5000"
            {...overlayProps}
            placement='top'
            onEntered={ () => this.hideTooltip()}
            ref={(el) => this.overlay = el}
            target={() => ReactDOM.findDOMNode(this.refs.target)}
          >
            <Tooltip show={ this.state.showTooltip } id="overload-right">{statusMessage}</Tooltip>
          </Overlay>
          <Button
            bsSize='xsmall'
            className='reset-password-link background-color-dark-grey'
            onClick={() => handleResetPassword(uuid, email)}
          >
            reset password
          </Button>
        </span>)

    return (
      <tr>
        <td>{uuid}</td>
        <td>{firstName}</td>
        <td>{lastName}</td>
        <td>{email}</td>
        <td>{button}</td>
      </tr>
    )
  }
导出类用户扩展组件{
构造函数(){
超级()
这个州{
showTooltip:正确
}
this.buttonEl=未定义
}
hideTooltip(){
setTimeout(()=>this.setState({showTooltip:false}),3000)
}
render(){
console.log(这个)
常数{
handleResetPassword,
重置电子邮件验证状态,
resetEmailValidationUser,
状态颜色,
statusMessage}=this.props,
{uuid,firstName,lastName,email}=this.props.user,
overlayProps={show:uuid==resetEmailValidationUser},
按钮=(
this.buttonEl=el}>
this.hideTooltip()}
ref={(el)=>this.overlay=el}
target={()=>ReactDOM.findDOMNode(this.refs.target)}
>
{statusMessage}
handleResetPassword(uuid,电子邮件)}
>
重置密码
)
返回(
{uuid}
{firstName}
{lastName}
{email}
{按钮}
)
}

我想你可以听Overlay
onenterned
并触发setState将show设置为false。比如:

export class User extends Component {
  constructor(){
    super()
    this.state {
      showTooltip: true
    }
    this.buttonEl = undefined
  }

  hideTooltip(){
     setTimeout(() => this.setState({ showTooltip: false }), 3000)
  }

  render() {
    console.log(this)
    const {
        handleResetPassword,
        resetEmailValidationState,
        resetEmailValidationUser,
        statusColor,
        statusMessage } = this.props,
      { uuid, firstName, lastName, email } = this.props.user,
      overlayProps = { show: uuid === resetEmailValidationUser},
      button = (
        <span ref={(el) => this.buttonEl = el}>
          <Overlay
            animation
            delayHide="5000"
            {...overlayProps}
            placement='top'
            onEntered={ () => this.hideTooltip()}
            ref={(el) => this.overlay = el}
            target={() => ReactDOM.findDOMNode(this.refs.target)}
          >
            <Tooltip show={ this.state.showTooltip } id="overload-right">{statusMessage}</Tooltip>
          </Overlay>
          <Button
            bsSize='xsmall'
            className='reset-password-link background-color-dark-grey'
            onClick={() => handleResetPassword(uuid, email)}
          >
            reset password
          </Button>
        </span>)

    return (
      <tr>
        <td>{uuid}</td>
        <td>{firstName}</td>
        <td>{lastName}</td>
        <td>{email}</td>
        <td>{button}</td>
      </tr>
    )
  }
导出类用户扩展组件{
构造函数(){
超级()
这个州{
showTooltip:正确
}
this.buttonEl=未定义
}
hideTooltip(){
setTimeout(()=>this.setState({showTooltip:false}),3000)
}
render(){
console.log(这个)
常数{
handleResetPassword,
重置电子邮件验证状态,
resetEmailValidationUser,
状态颜色,
statusMessage}=this.props,
{uuid,firstName,lastName,email}=this.props.user,
overlayProps={show:uuid==resetEmailValidationUser},
按钮=(
this.buttonEl=el}>
this.hideTooltip()}
ref={(el)=>this.overlay=el}
target={()=>ReactDOM.findDOMNode(this.refs.target)}
>
{statusMessage}
handleResetPassword(uuid,电子邮件)}
>
重置密码
)
返回(
{uuid}
{firstName}
{lastName}
{email}
{按钮}
)
}

您可以使用
OverlayTrigger
组件而不是overlay。
clickOnButton
功能将
show
标志设置为true,然后在1秒后再次将其设置为false

clickOnButton = () => {
    this.setState({
        show: true
    });

    setTimeout( () => {this.setState({show: false}); }, 1000);
    };


renderTooltip(props) {
    return <Tooltip {...props}>Copied!</Tooltip>;
  }


renderNothing(props) {
    return <div />
  }

您可以使用
OverlayTrigger
组件而不是overlay。
clickOnButton
功能将
show
标志设置为true,然后在1秒后再次将其设置为false

clickOnButton = () => {
    this.setState({
        show: true
    });

    setTimeout( () => {this.setState({show: false}); }, 1000);
    };


renderTooltip(props) {
    return <Tooltip {...props}>Copied!</Tooltip>;
  }


renderNothing(props) {
    return <div />
  }

延迟隐藏是否足够?不,我设置了,但你必须先隐藏它,你必须设置隐藏,但我需要能够检测到它以某种方式显示以设置隐藏,或者我猜你可以尝试隐藏覆盖本身,但我仍然不知道如何做哇,这一定很棘手,没有任何人的回应不够吗?不,我设置了,但你必须先隐藏它,你必须设置隐藏,但我需要能够检测到它以某种方式显示以设置隐藏,或者我猜你可以尝试隐藏覆盖本身,但我仍然不知道如何做哇,这一定很棘手,没有任何人的回应,或者我猜你可以尝试隐藏覆盖层本身,但我仍然不知道如何做,或者我猜你可以尝试隐藏覆盖层本身,但我仍然不知道如何做