Last active
October 17, 2017 04:44
-
-
Save hql287/8ad4663feb2f516a6a86a306c8947cb0 to your computer and use it in GitHub Desktop.
Self Closing Notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Notification extends Component { | |
constructor(props) { | |
super(props); | |
this.removeNoti = this.removeNoti.bind(this); | |
} | |
componentDidMount() { | |
this.timeout = setTimeout(this.removeNoti, 4000); | |
} | |
shouldComponentUpdate(nextProps) { | |
return this.props.notification !== nextProps.notification; | |
} | |
componentWillUnmount() { | |
clearTimeout(this.timeout); | |
} | |
removeNoti() { | |
const {removeNoti, notification} = this.props; | |
removeNoti(notification.id); | |
} | |
render() { | |
const {notification} = this.props; | |
return ( | |
<Noti type={notification.type} onClick={this.removeNoti}> | |
<Message> | |
{notification.message} | |
</Message> | |
<Button onClick={this.removeNoti}> | |
Close | |
</Button> | |
</Noti> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment