useSidebar must be used within a SidebarProvider even in an absolutely minimal example #7543
-
Hello, I just tried the Sidebar component for the first time, and I can't even get a very minimal example working in my dev environment. I just installed it as per instructions by
Chrome console shows:
And I'm using very minimal React app:
The app-sidebar being directly copypasted from the ShadCN website:
The webpage that loads the React app is within a .NET 8 application, quite simple as well:
Am I missing something obvious? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, the Its from the sidebar documentation: https://ui.shadcn.com/docs/components/sidebar import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar"
import { AppSidebar } from "@/components/app-sidebar"
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<SidebarProvider>
<AppSidebar />
<main>
<SidebarTrigger />
{children}
</main>
</SidebarProvider>
)
} Please take another look at the documentation on the shadcn website, please try to read till the end. Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey, the
AppSidebar
must be wrapped inside aSidebarProvider
, the provider handles the collapsible state. You can refer to this diagram for the way sidebar is structured:Its from the sidebar documentation: https://ui.shadcn.com/docs/components/sidebar
If you scroll down below in this documentation you can see an example of
AppSidebar
usage: