Skip to content

Commit

Permalink
fix first render of sidebar collpased string query
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiralucas committed Jan 6, 2025
1 parent cb999aa commit a3db0da
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apps/web/src/hooks/useSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
useContext,
useState,
} from 'react'
import { useStringQuery } from './useQueryArgs'

type Context = [boolean, Dispatch<SetStateAction<boolean>>]
const Context = createContext<Context>([true, () => {}] as unknown as Context)
Expand All @@ -15,8 +14,10 @@ export default function useSideBar(): Context {
}

export function SideBarProvider({ children }: { children: React.ReactNode }) {
const noSidebarQs = useStringQuery('sidebarCollapsed')
const value = useState(noSidebarQs === 'true')
const value = useState(
() =>
new URLSearchParams(location.search).get('sidebarCollapsed') !== 'true'
)

return <Context.Provider value={value}>{children}</Context.Provider>
}

0 comments on commit a3db0da

Please sign in to comment.