Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
NextJS - Component.name have different value on BUILD

I have a pages that have different Layouts. Inorder to Switch Layout I am using the Component.name in _app.js. It is working in Development but after building the project and using the npm start. It seems the Component.name doesn't contain the correct value making the Layout Component used by other pages.


      if (Component.name === 'Login') {
        return <Component {...{ pageProps, toast }} />;
      }
      return (
        <Layout>
          <Component {...{ pageProps, toast }} />
        </Layout>
      );

Is there something that I have missed here? Or this is not the correct way to implement something like this.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I am facing the same issue. After some digging, it turns out it was because files were minified in production. We can set the component name explicitly before we export, then we should be able to access it in production.

// Login Component
function Login() {....}

Login.displayName = "Login"

export default Login;

then you can access it with

      if (Component.displayName === 'Login') {
        return <Component {...{ pageProps, toast }} />;
      }
      return (
        <Layout>
          <Component {...{ pageProps, toast }} />
        </Layout>
      );
about 4 years ago · Juan Pablo Isaza Report

0

You could use the pathname of the router here to check this:

  if (["/login"].includes(router.pathname)) {
    return <Component {...{ pageProps, toast }} />;
  }
  return (
    <Layout>
      <Component {...{ pageProps, toast }} />
    </Layout>
  );
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!