Next.js use of _app.js and _document.js

Short answer: Yes, You can use both. They serve different purpose and can be used in the same application.

According to NextJS docs:

Next.js uses the App component to initialize pages.

To override, create the ./pages/_app.js file and override the App class

and

Pages in Next.js skip the definition of the surrounding document’s markup. For example, you never include <html>, <body>, etc. To override that default behavior, you must create a file at ./pages/_document.js, where you can extend the Document class.

Note: _document.js is only rendered on the server side and not on the client side. so event handlers like onClick is not going to work.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)