#How can I pass props from a page to _app.tsx?

16 messages · Page 1 of 1 (latest)

quick torrent
#

I have this in my _app.tsx:

export default function App({ Component, pageProps }: AppProps) {
  return (
    <Layout>
      <Component {...pageProps} />
    </Layout>
  )
}

I'd like to pass variables like menu_bg=white, etc. to Layout here. For example, I'd like to change menu bar color per page.

#

should I just hack something like Component.data = {}?

wicked mortar
quick torrent
#

That part is 100% client side

#

thanks!

quick torrent
#

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?

wicked mortar
#

Your first message was for the pages directory but this one is for the app directory

#

They are very very different

quick torrent
#

pages

#

I'm following the Layout docs for pages, but added <html> inside <Head>

<Head>
  <html className={clsx({ dark })} />
wicked mortar
quick torrent
#

yes

#

i created one

wicked mortar