// @flow import React from 'react'; import { connect } from 'react-redux'; import { closeNotification } from 'actions/notifications'; import type { Notification } from 'actions/notifications'; class NotificationRow extends React.Component { props: { notification: Notification, onClose: (n: Notification) => void }; render() { const { msg, level } = this.props.notification; let className = ''; switch (level) { case 'danger': className = 'alert-danger'; break; case 'success': className = 'alert-success'; break; case 'warning': className = 'alert-warning'; break; } return (
{level}
); } onClose = () => { this.props.onClose(this.props.notification); }; } export class Notifications extends React.Component { props: { notifications: Notification[], closeNotification: (n: Notification) => void }; render() { if (!this.props.notifications.length) { return null; } return (
{this.props.notifications.map((n, i) => )}
); } } const mapStateToProps = state => ({ notifications: state.notifications }); export default connect(mapStateToProps, { closeNotification })(Notifications);