Created
June 28, 2017 02:29
-
-
Save jakesorce/44f9e790798e61969354df9d72ee9b7e to your computer and use it in GitHub Desktop.
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
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