schiehll / react-alert

alerts for React
MIT License
608 stars 98 forks source link

How do I close alert without button #97

Closed marcelabomfim closed 5 years ago

marcelabomfim commented 5 years ago

I have an alert that is displayed while a xhr download request is being processed, and another alert that is displayed when the download is ready. How do I do that ?

componentWillReceiveProps(nextProps) {
    const { downloadStatus } = this.props;
    if (!downloadStatus.isLoading && nextProps.downloadStatus.isLoading) {
      this.props.alert.info('Download is loading...', { time: 0 });
    } else if (downloadStatus.isLoading && !nextProps.downloadStatus.isLoading) {
      // here i have to close info alert and show success
      this.props.alert.success('Download is ready!', { time: 2000 });
    }
  }
jacobsowles commented 5 years ago

You can programmatically remove an alert by using this.props.alert.remove(alert).

marcelabomfim commented 5 years ago

This is exactly what I wanted, thank you @jacobsowles