Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reactstrap alert automatic hidden

I am new in React and I use Alert - Dismissing from Reactstrap , I need the alert to automatically disappear after 2s. I tried to find some function that could be done, but unfortunately I did not. Thank you for help

like image 854
user3468921 Avatar asked Dec 23 '22 03:12

user3468921


2 Answers

Please have a look at this code, hiding alert after a specific time

when you want to show the alert on some action, you can enable a state associated with that alert and disable it when you want to hide it.

like image 108
Shubham Avatar answered Jan 15 '23 04:01

Shubham


I had a similar problem. My purpose was to show an Alert message after a Modal closed. I am using react-bootstrap for Modal and Alert component with useState and use Effects hooks.

const [visibleAlert, setVisibleAlert] = useState(false); --> init state

const handleVisible = () => { ---> Last State for Alert
    setAlertVisible(true)
    setTimeout(() => { ---> 2 seconds later which is closing
        setAlertVisible(false)
    }, 2000);
} 

useEffect(() => {

    handleClose();  ----> This is for Modal
    return () => {
    handleVisible();  ---> This is for Alert message
};

And this is my Alert component.

<Alert show={visibleAlert} variant="success"} dismissible>
    Employee List Updated Successfully.
</Alert>
like image 40
Arin Yazilim Avatar answered Jan 15 '23 04:01

Arin Yazilim