Skip to content

Commit ebfd6a5

Browse files
Copilothotlong
andcommitted
Refactor: Extract DEFAULT_SIDEBAR_STATE constant for better maintainability
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 7454abd commit ebfd6a5

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

packages/components/src/ui/sidebar.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,22 @@ type SidebarContextProps = {
5252

5353
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
5454

55+
// Default sidebar state for when no provider exists (e.g., during SSR/prerendering)
56+
const DEFAULT_SIDEBAR_STATE: SidebarContextProps = {
57+
state: "expanded",
58+
open: true,
59+
setOpen: () => {},
60+
openMobile: false,
61+
setOpenMobile: () => {},
62+
isMobile: false,
63+
toggleSidebar: () => {},
64+
}
65+
5566
function useSidebar() {
5667
const context = React.useContext(SidebarContext)
5768
if (!context) {
58-
// Return default values when no provider exists (e.g., during SSR/prerendering)
59-
// This allows components to gracefully degrade without breaking the build
60-
return {
61-
state: "expanded" as const,
62-
open: true,
63-
setOpen: () => {},
64-
openMobile: false,
65-
setOpenMobile: () => {},
66-
isMobile: false,
67-
toggleSidebar: () => {},
68-
}
69+
// Return default values to allow components to gracefully degrade without breaking the build
70+
return DEFAULT_SIDEBAR_STATE
6971
}
7072

7173
return context

0 commit comments

Comments
 (0)