#How can I pass props from a page to _app.tsx?
16 messages · Page 1 of 1 (latest)
If the prop is sent from getStaticProps or getServerSideProps, it’s already available in pageProps. Otherwise yes, you do it that way
It works well, except for one bug: the <html> element inside <Head> in Layout.tsx doesn't update when navigating between pages.
That is: reloading the page makes it work, but simply navigating doesn't update the html.
Or for phrasing this question differently, I'm looking for the simplest possible Next.js app which has 2 pages, with with <html className="dark"> and one without. How would you do this?
Are you using the app directory or the pages directory?
Your first message was for the pages directory but this one is for the app directory
They are very very different
pages
I'm following the Layout docs for pages, but added <html> inside <Head>
<Head>
<html className={clsx({ dark })} />
In the pages directory there is no such thing as layout.tsx? Or did you mean a custom layout component?
yes
i created one
anyway, it's like so
export default function App({ Component, pageProps }: AppProps) {
// if you use Page,title, it will be available here as Component.title
// if you return the prop from getStaticProps or getServerSideProps,
// it will be available here as pageProps.title
// use the way you prefer
return ...;
}