menu
up-caret
down-caret

Next.js

A place to chat about Next.js and answer questions. For all other ZEIT products, check this out.

# General

General Chatter

Trending conversations
I am trying to add React OWL Carousel.
@adilsaeed31 · 7h
pages, best practices and anti-patterns
@markymark · 10h
next-routes not working with next 7 ?
@kokno · 12d
How should a nested layout be implemented?
@seekcx · 40d
Using a sub-folder when running a custom express server
@madsobel · 40d

Is there an example of _app.js as a functional component?

Peter Kellner (@pkellner) · January 15, 2019 at 6:01am

Is there an example of _app.js as a functional component?

January 15, 2019 at 6:01am

I'm trying to use React Hooks with it and the only example is here in the docs:

https://nextjs.org/docs/#custom-app

I've tried a few ways to make it work but it keeps breaking my app. Hoping there is an example someplace.


January 15, 2019 at 10:58am

You can't, it has to extend the parent app component

  • reply
  • like

Instead you can just render another component

  • reply
  • like
function MyOtherComponent({children}) {
const something = useSomeHook()
return <div>{children}</div>
}
// And then inside of _app.js render()
<Container><MyOtherComponent><Component></MyOtherComponent></Container>
  • reply
  • like