Next.js app folder: is there some “entry point”? A direct replacement for _app.tsx?

On the Upgrade Guide page, they say pages/_app.js and pages/_document.js have been replaced with a single app/layout.js root layout”.

So in your case, you can put your logic there and make it a client component with "use client" at the top if you want client interactivities like a useEffect in it.

But say you don’t want your root layout to be a client component, you could do as below, for example, using a separate component:

// DefineCustomElements.js

"use client";

export default function DefineCustomElements() {
  useEffect(() => defineCustomElements(), []);

  return <></>;
}

// app/layout.js

import DefineCustomElements from "./DefineCustomElements";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <DefineCustomElements />
        {children}
      </body>
    </html>
  );
}

Leave a Comment