import React, { useEffect, useState } from 'react'; import Bus from '../../notifications'; export const Flash = () => { let [visibility, setVisibility] = useState(false); let [message, setMessage] = useState(''); let [color, setColor] = useState(''); let flashListener = ({message, color}) => { setVisibility(true); setMessage(message); setColor(color); setTimeout(() => { setVisibility(false); }, 4000); } useEffect(() => { Bus.addListener('flash', flashListener); return function () { Bus.removeListener('flash', flashListener); } }, []); return ( visibility &&

{message}

) }