question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use getLayout function to customize layout

See original GitHub issue

As it’s written on the official docs.

// pages/index.js

import Layout from '../components/layout'
import NestedLayout from '../components/nested-layout'

export default function Page() {
  return {
    /** Your content */
  }
}

Page.getLayout = function getLayout(page) {
  return (
    <Layout>
      <NestedLayout>{page}</NestedLayout>
    </Layout>
  )
}
// pages/_app.js

export default function MyApp({ Component, pageProps }) {
  // Use the layout defined at the page level, if available
  const getLayout = Component.getLayout || ((page) => page)

  return getLayout(<Component {...pageProps} />)
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Dannymxcommented, Aug 20, 2022

I think the getLayout pattern should be implemented.

2reactions
riollycommented, Jul 4, 2022

We use that pattern to avoid rerendering the layout component when navigating to a page with the same layout. (mimicking client-side navigation) And I think those who use this template have been familiar with next.js and (the other tech stack inside it) and will end up in that situation also.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic Features: Layouts - Next.js
When using TypeScript, you must first create a new type for your pages which includes a getLayout function. Then, you must create a...
Read more >
Persistent Layout Patterns in Next.js - Adam Wathan
Option 1: Use a single shared layout in a custom `<App>` component ... Option 4: Add a `getLayout` function to your page components....
Read more >
5 - getLayout function on page and layout components
5 - getLayout function on page and layout components. 16. Embed Fork Create Sandbox Sign in. Sandbox Info. 5 - getLayout function on...
Read more >
Next.js #7 - Custom Layouts - YouTube
Support the Channel:Become a Member: https://www.youtube.com/ansonthedeveloper/joinBecome a Patreon: http://patreon.com/stuyyBuy me a ...
Read more >
How to wrap components that use the getLayout() method
This works, but the layout persistence simply doesn't work. It removes all benefits from the first example. Is it possible to fix this?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found