For example, in api-routes
we have this example
export default (req, res) => {
res.statusCode = 200
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify({ name: 'John Doe' }))
}
Exporting anonymous functions is arguably bad practice. If this agreed upon, I think any examples containing anonymous exports should be changed to use named functions
Feel free to send a PR.
Hey, if this issue is not assigned to anyone, can I take this up?
If yes, should I use arrow functions or regular functions?
For sure @jashnm, regular functions is fine!
Obviously the PR is going to be reviewed by one of the Next.js maintainers but I wanted to say that it looks good to me. Nice contribution @Jashnm !
Why is exporting anonymous functions a bad practice? @awareness481
@lcswillems
import something from 'somewhere' // Something is internally called foo though
import { foo as something } from 'somewhere' // can find-replace foo easily here
this goes hand in hand with better refactoring support in editors
Personally, I consider default exports to be bad practice because of mentioned reasons and actively lint against them. In places where I _have to_ use default exports, e.g. nextjs pages, I // eslint-disable-next-line import/no-default-export.
Thank you for your answer @ljosberinn !