4 ms·
Anyone have an idea why it suggests named functions instead of arrow functions for functional components?
by FLGMwt 9y ago
Anyone have an idea why it suggests named functions instead of arrow functions for functional components?
- wiesson 9y agoI guess debugging is easier with named functions. Arrow functions don't have names See here: https://github.com/yannickcr/eslint-plugin-react/issues/412 https://github.com/yannickcr/eslint-plugin-react/issues/412
- FLGMwt 9y agoThat was roughly my guess. I asked because I ran into a specific edge case where this is finicky. AFAIK, arrow functions do (and should) have names if they're assigned to a variable. const foo = () => {}; // undefined foo.name // "foo" I ran into a specific bug where this doesn't work for the following case when using babel to target modern versions of node: export const foo = () => {}; Note that's only when the declaration is part of an export (https://github.com/babel/babel/issues/7194 https://github.com/babel/babel/issues/7194). The name works fine in the browser, but since jest/enzyme use node to run tests, I had issues with functional components (defined as arrow functions and immediately exported) were missing their names. FWIW, this isn't an issue in Babel 7.