Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 26 additions & 38 deletions src/NotificationContainer.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,41 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import NotificationManager from './NotificationManager';
import Notifications from './Notifications';

class NotificationContainer extends React.Component {
static propTypes = {
enterTimeout: PropTypes.number,
leaveTimeout: PropTypes.number
};

static defaultProps = {
enterTimeout: 400,
leaveTimeout: 400
};

state = {
notifications: []
};
const NotificationContainer = ({
enterTimeout = 400,
leaveTimeout = 400
}) => {
const [notifications, setNotifications] = useState([]);

componentWillMount = () => {
NotificationManager.addChangeListener(this.handleStoreChange);
};
useEffect(() => {
NotificationManager.addChangeListener(handleStoreChange);

componentWillUnmount = () => {
NotificationManager.removeChangeListener(this.handleStoreChange);
};
NotificationManager.removeChangeListener(handleStoreChange);
});

handleStoreChange = (notifications) => {
this.setState({
notifications
});
const handleStoreChange = newNotifications => {
setNotifications(newNotifications)
};

handleRequestHide = (notification) => {
const handleRequestHide = (notification) => {
NotificationManager.remove(notification);
};

render() {
const { notifications } = this.state;
const { enterTimeout, leaveTimeout } = this.props;
return (
<Notifications
enterTimeout={enterTimeout}
leaveTimeout={leaveTimeout}
notifications={notifications}
onRequestHide={this.handleRequestHide}
/>
);
}
return (
<Notifications
enterTimeout={enterTimeout}
leaveTimeout={leaveTimeout}
notifications={notifications}
onRequestHide={handleRequestHide}
/>
);
}

NotificationContainer.propTypes = {
enterTimeout: PropTypes.number,
leaveTimeout: PropTypes.number
};

export default NotificationContainer;