Next.js: Allow export page component as named not default

Created on 2 Aug 2019  路  2Comments  路  Source: vercel/next.js

It's easier to write.

export function Home() {
  return <div>Welcome to Next.js!</div>;
}

Default export sucks. It's ambiguous. The reason why default export exists is backward interoperability with CommonJS.

Most helpful comment

Would be nice to support this. If a code base has the convention (and lint rules) forbidding default exports, making the codebase have to make an exception for each page is not ideal.

The convention could be to look for a default export and then look for an export named page if not default export is not found.

All 2 comments

This needlessly increases the API surface of Next.js, considering you shouldn't be ever self-importing your pages.

How would Next.js know what export is your page? Default is the only safe assumption.

Thanks for the suggestion, though.

Would be nice to support this. If a code base has the convention (and lint rules) forbidding default exports, making the codebase have to make an exception for each page is not ideal.

The convention could be to look for a default export and then look for an export named page if not default export is not found.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olifante picture olifante  路  3Comments

rauchg picture rauchg  路  3Comments

kenji4569 picture kenji4569  路  3Comments

swrdfish picture swrdfish  路  3Comments

irrigator picture irrigator  路  3Comments