Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't export an arrow function as default from a page #21

Closed
hazae41 opened this issue Nov 8, 2020 · 1 comment
Closed

Can't export an arrow function as default from a page #21

hazae41 opened this issue Nov 8, 2020 · 1 comment

Comments

@hazae41
Copy link
Member

hazae41 commented Nov 8, 2020

The default syntax is

export default function Home(){
  // ...
}

but when I use an arrow function

export default () => {
  // ...
}

I get a blank page with 400 - Module "undefined" should export a React Component as default

However, it works when declaring then exporting

const Home = () => {
  // ...
}

export default Home

or when using forwardRef

export default forwardRef((props, ref) => {
  // ...
})

It would be great if we allowed arrow functions as well as regular functions, what do you think about it?

@ije
Copy link
Member

ije commented Nov 8, 2020

sorry, alephjs will check the module's export default ensure it's a validate component:

  • must be a function component or class component extends React.Component(don't support fast refresh)
  • function component must be named with /^[A-Z]/

best practice with arrow function is:

const Home = () => {
  // ...
}

export default Home

@hazae41 hazae41 closed this as completed Nov 8, 2020
mohsenkhanpour pushed a commit to mohsenkhanpour/aleph.js that referenced this issue Jan 29, 2021
doc: fix name placeholder for Dynamic API Routes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants