AppNotificationItem.tsx 961 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React, { Component } from 'react';
  2. import { AppNotification } from 'app/types';
  3. import { AlertBox } from '../AlertBox/AlertBox';
  4. interface Props {
  5. appNotification: AppNotification;
  6. onClearNotification: (id) => void;
  7. }
  8. export default class AppNotificationItem extends Component<Props> {
  9. shouldComponentUpdate(nextProps) {
  10. return this.props.appNotification.id !== nextProps.appNotification.id;
  11. }
  12. componentDidMount() {
  13. const { appNotification, onClearNotification } = this.props;
  14. setTimeout(() => {
  15. onClearNotification(appNotification.id);
  16. }, appNotification.timeout);
  17. }
  18. render() {
  19. const { appNotification, onClearNotification } = this.props;
  20. return (
  21. <AlertBox
  22. severity={appNotification.severity}
  23. title={appNotification.title}
  24. text={appNotification.text}
  25. icon={appNotification.icon}
  26. onClose={() => onClearNotification(appNotification.id)}
  27. />
  28. );
  29. }
  30. }