Skip to content

Commit

Permalink
Delay initial mount
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Dec 3, 2024
1 parent 26d95a3 commit 9be95bf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/sidebar/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useState, type ReactElement } from 'react'
import { useCallback, useEffect, useState, type ReactElement } from 'react'
import { Box, Divider, Drawer } from '@mui/material'
import ChevronRight from '@mui/icons-material/ChevronRight'

Expand All @@ -14,6 +14,7 @@ import MyAccounts from '@/features/myAccounts'

const Sidebar = (): ReactElement => {
const [isDrawerOpen, setIsDrawerOpen] = useState<boolean>(false)
const [keepMounted, setKeepMounted] = useState(false)

const onDrawerToggle = useCallback(() => {
setIsDrawerOpen((isOpen) => {
Expand All @@ -25,6 +26,13 @@ const Sidebar = (): ReactElement => {

const closeDrawer = useCallback(() => setIsDrawerOpen(false), [])

// Mount the drawer 600ms after the page load, and keep it mounted
useEffect(() => {
setTimeout(() => {
setKeepMounted(true)
}, 600)
}, [])

return (
<div data-testid="sidebar-container" className={css.container}>
<div className={css.scroll}>
Expand Down Expand Up @@ -63,7 +71,7 @@ const Sidebar = (): ReactElement => {
anchor="left"
open={isDrawerOpen}
onClose={onDrawerToggle}
ModalProps={{ keepMounted: true }}
ModalProps={{ keepMounted }}
>
<div className={css.drawer}>
<MyAccounts onLinkClick={closeDrawer} isSidebar></MyAccounts>
Expand Down

0 comments on commit 9be95bf

Please sign in to comment.