Generating a Layout with main AND sidebar content??

How would I go about creating a <Layout /> that will allow me to pass in children to define the body content AND sidebar content? So I'm expecting each page to have the Header, provided by the Layout, and then two children. The first child will be the body content, the second will be the sidebar. Is there a way to write a Layout that will accept specific children in specific places?
17 Replies
Amos
Amos•3y ago
Just create a different layout when it's supposed to be different? LayoutWithSidebar and LayoutWithoutSidebar 😀
Donny D
Donny DOP•3y ago
well I want the layout to be the same, just the content to change
iDarkLightning
iDarkLightning•3y ago
Just use props?
Amos
Amos•3y ago
The content is the page, so what's the problem there?
Donny D
Donny DOP•3y ago
I tried doing a layout and just using children[0] and children[1] for putting the body content and sidebar content in their respective containers. .....it seems to actually work perfectly
Amos
Amos•3y ago
Check https://nextjs.org/docs/basic-features/layouts, but I mean all this will be redundant once they release their next version
iDarkLightning
iDarkLightning•3y ago
I really wouldn't do this, it's very unclear and very breakable Your consumer hasn't the faintest clue that this is what will happen
Donny D
Donny DOP•3y ago
what do you mean?
iDarkLightning
iDarkLightning•3y ago
If someone else uses your layout, why would they think that you're putting the content in different places like that
Donny D
Donny DOP•3y ago
It's not for an open-source project. And I think it's fairly easy to pick up on from reading the source code on a page you just do
<Layout>
<div>this is the body content</div>
<div>this will appear in the sidebar</div>
</Layout>
<Layout>
<div>this is the body content</div>
<div>this will appear in the sidebar</div>
</Layout>
iDarkLightning
iDarkLightning•3y ago
Why not just use props
Donny D
Donny DOP•3y ago
you mean like define a sideBar prop on the Layout component?
iDarkLightning
iDarkLightning•3y ago
Yeah
Donny D
Donny DOP•3y ago
I could....but that sounds less........ sexy to me. and children already is a prop, so I'd be writing a new prop to do something that's already technically being done
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Develliot
Develliot•3y ago
I would do
<Layout sidebar={<Sidebar/>}>
<Content/>
</Layout>
<Layout sidebar={<Sidebar/>}>
<Content/>
</Layout>
` It's almost always about what is the least brittle, most performant, more standard convention, more easy to follow, way before ticks and sexiness. React gives you a lot of rope to hang yourself sometimes.
Glorrin
Glorrin•3y ago
how many different sidebar do you need ? you could do : <Layout sidebarType={"default" | "empty" | "fancy"}> <Content/> </Layout> And define your sidebars inside Layout
Want results from more Discord servers?
Add your server