-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathcontainer.js
More file actions
63 lines (50 loc) · 1.44 KB
/
container.js
File metadata and controls
63 lines (50 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React, {PropTypes} from 'react';
import {connect} from 'react-redux';
import ReactDOM from 'react-dom';
import Notifications from 'react-notification-system-redux';
const notificationOpts = {
// uid: 'once-please', // you can specify your own uid if required
title: 'Hey, it\'s good to see you!',
message: 'Now you can see how easy it is to use notifications in React!',
position: 'tr',
autoDismiss: 0,
action: {
label: 'Click me!!',
callback: () => alert('clicked!')
}
};
class Container extends React.Component {
constructor() {
super();
this.handleClick = this.handleClick.bind(this);
}
dispatchNotification(fn, timeout) {
setTimeout(() => {
this.context.store.dispatch(fn(notificationOpts));
}, timeout);
}
handleClick() {
this.dispatchNotification(Notifications.success, 250);
this.dispatchNotification(Notifications.error, 500);
this.dispatchNotification(Notifications.warning, 750);
this.dispatchNotification(Notifications.info, 1000);
}
render() {
const {notifications} = this.props;
return (
<div>
<button onClick={this.handleClick}>Spawn some notifications!!!</button>
<Notifications notifications={notifications} />
</div>
);
}
}
Container.contextTypes = {
store: PropTypes.object
};
Container.propTypes = {
notifications: PropTypes.object
};
export default connect(
state => ({ notifications: state.notifications })
)(Container);