-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Require function declaration for named components #33
Conversation
Hmm, this will disallow using arrow functions for components at all though. I mostly use function declaration for exported components. It's nice to be able to define using arrow function for non-exported components. Thoughts? |
Co-authored-by: Sindre Sorhus <[email protected]>
Recently, I've been shifting away from overusing Arrow functions are for functions that can fit entirely on one line and that is rarely an entire React component. |
Given this, adding brackets around components that are returned may become more of an annoyance since we would no longer need to make it explicitly clear where our components are since it would be implied by the |
I agree with your reasoning. Let's try it out. |
unsolicited opinion here 😉 |
One thing that I've noticed while updating code to comply with this rule is you can no longer effectively use the TypeScript types provided by Take this snippet for example: import type {FC} from 'react';
interface Props {
href?: string;
}
const Button: FC<Props> = props => (
<a href={props.href} className='btn'>
<p>{props.children}</p>
</a>
);
export default Button; How should this code be updated? You can turn |
Yes, that's a legitimate use case. We'd need to detect whether TypeScript types are used on the variable which may be difficult. Perhaps it is easier to disable the rule or make it much more lenient? |
Did you do a performance comparison? Could arrow functions be optimized way more by the JIT than regular functions? |
Arrow functions perform very slightly better since they don't need to allocate a |
Fixes #32