Explain the use of Custom App (_app.js) and Custom Document (_document.js) in Next.js.

Instruction: Discuss the purposes and differences between Custom App and Custom Document in a Next.js application.

Context: This question is designed to evaluate the candidate's knowledge of extending the default structure and behavior of Next.js applications using _app.js and _document.js files.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

These are Pages Router conventions with different responsibilities.

pages/_app.js wraps the active page. Its Component prop is the selected page component, and pageProps contains that page's initial props. It is a useful place for shared providers, a stable application shell and global CSS imports. State in a shared wrapper can survive client navigation when React preserves its identity; remounting or changing keys can reset it...

Related Questions