fix(phone/snackbar): Fixed animations & simplified logic (#146)

This commit is contained in:
Taso authored and GitHub committed 2021-03-06 17:32:01 -05:00
1 parent e56ae415dc
commit 6e72e2c50e
5 files changed
+27 -24

No files matched your search

+13 -13
View File
@@ -1,23 +1,23 @@
import React, { createContext, useState, useEffect, useRef } from 'react';
import React, { createContext, useState } from 'react';
import { IAlert } from '../hooks/useSnackbar';
export const SnackbarContext = createContext(null);
function SnackbarProvider({ children }) {
const [alert, setAlert] = useState(null);
const timer = useRef(null);
const [open, setOpen] = useState<boolean>(false);
const [alert, setAlert] = useState<IAlert>(null);
useEffect(() => {
if (alert) {
clearTimeout(timer.current);
timer.current = setTimeout(() => {
setAlert(null);
}, 2000);
}
return () => clearTimeout(timer.current);
}, [alert]);
const setNewAlert = (alert: IAlert) => {
setAlert(alert);
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<SnackbarContext.Provider value={{ alert, addAlert: setAlert }}>
<SnackbarContext.Provider value={{ alert, addAlert: setNewAlert, handleClose, isOpen: open }}>
{children}
</SnackbarContext.Provider>
);