diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-12 03:31:56 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-12 03:31:56 +0300 |
commit | fc63251148397c2c9b2318c898b25d08066ee6b1 (patch) | |
tree | 8a39bb40b245d9befa79e197d3a82952f7be13ae /src/components/Drawer/Drawer.tsx | |
parent | e8b66d8fcea497be8b1820cde8ec187383b70c60 (diff) | |
download | which-ui-fc63251148397c2c9b2318c898b25d08066ee6b1.tar.gz |
feat: close drawer on history updates
Diffstat (limited to 'src/components/Drawer/Drawer.tsx')
-rw-r--r-- | src/components/Drawer/Drawer.tsx | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/components/Drawer/Drawer.tsx b/src/components/Drawer/Drawer.tsx index eded40c..76b5120 100644 --- a/src/components/Drawer/Drawer.tsx +++ b/src/components/Drawer/Drawer.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import React, { useMemo, useEffect, useCallback } from 'react'; import { useHistory } from 'react-router-dom'; import { SwipeableDrawer, @@ -33,23 +33,27 @@ const Drawer: React.FC<PropTypes> = React.memo(({ isOpen, setIsOpen }) => { const history = useHistory(); const { user, logout } = useAuth(); - const handleOpen = () => { + const handleOpen = useCallback(() => { setIsOpen(true); - }; + }, [setIsOpen]); - const handleClose = () => { + const handleClose = useCallback(() => { setIsOpen(false); - }; + }, [setIsOpen]); - const handleLogout = () => { + useEffect(() => { + // Close drawer on navigations + return history.listen(() => handleClose()); + }, [history, handleClose]) + + const handleLogout = useCallback(() => { logout(); - handleClose(); - }; + history.push('/login'); + }, [logout, history]); - const handleAbout = () => { + const handleAbout = useCallback(() => { history.push('/'); - handleClose(); - }; + }, [history]); const iOS = useMemo(() => { return /iPad|iPhone|iPod/.test(navigator.userAgent); |