5dd4999b64
Strategized with @balazsorban44 to open one larger PR, with changes to individual examples as separate commits. For each example, I researched how multiple realworld codebases use the featured technology with TypeScript, to thoughtfully convert them by hand - nothing automated whatsoever. ## Documentation / Examples - [X] Make sure the linting passes by running `pnpm lint` - [X] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
45 lines
1.4 KiB
XML
45 lines
1.4 KiB
XML
import type { NextPageWithLayout } from './_app'
|
||
import Layout from '../components/layout'
|
||
import Sidebar from '../components/sidebar'
|
||
|
||
const About: NextPageWithLayout = () => {
|
||
return (
|
||
<section>
|
||
<h2>Layout Example (About)</h2>
|
||
<p>
|
||
This example adds a property <code>getLayout</code> to your page,
|
||
allowing you to return a React component for the layout. This allows you
|
||
to define the layout on a per-page basis. Since we're returning a
|
||
function, we can have complex nested layouts if desired.
|
||
</p>
|
||
<p>
|
||
When navigating between pages, we want to persist page state (input
|
||
values, scroll position, etc.) for a Single-Page Application (SPA)
|
||
experience.
|
||
</p>
|
||
<p>
|
||
This layout pattern will allow for state persistence because the React
|
||
component tree is persisted between page transitions. To preserve state,
|
||
we need to prevent the React component tree from being discarded between
|
||
page transitions.
|
||
</p>
|
||
<h3>Try It Out</h3>
|
||
<p>
|
||
To visualize this, try tying in the search input in the{' '}
|
||
<code>Sidebar</code> and then changing routes. You'll notice the input
|
||
state is persisted.
|
||
</p>
|
||
</section>
|
||
)
|
||
}
|
||
|
||
export default About
|
||
|
||
About.getLayout = function getLayout(page: React.ReactElement) {
|
||
return (
|
||
<Layout>
|
||
<Sidebar />
|
||
{page}
|
||
</Layout>
|
||
)
|
||
}
|