Skip to content

Instantly share code, notes, and snippets.

@jakesorce
Created June 28, 2017 02:29
Show Gist options
  • Save jakesorce/44f9e790798e61969354df9d72ee9b7e to your computer and use it in GitHub Desktop.
Save jakesorce/44f9e790798e61969354df9d72ee9b7e to your computer and use it in GitHub Desktop.
import React from 'react';
import { connect } from 'react-redux';
import { clearFlash } from '../actions/flash.js';
import '../styles/flash.css';
const fadeFlash = (dispatch) => {
setTimeout( () => {
dispatch(clearFlash())
}, 15000)
}
const Flash = ({ flash, dispatch }) => {
if (flash.message) {
return (
<div
id="alert"
className={`alert alert-${flash.msgType} center`}
style={{ width: '90%', margin: '0 auto'}}
onClick={ (e) => {
e.preventDefault();
dispatch(clearFlash())
}}
>
{flash.message}
{ fadeFlash(dispatch) }
</div>
)
} else {
return null
}
}
const mapStateToProps = (state) => {
return { flash: state.flash }
}
export default connect(mapStateToProps)(Flash);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment