Skip to content

Allow custom component parent classes #1856

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

Closed
haggholm opened this issue Jun 26, 2018 · 3 comments
Closed

Allow custom component parent classes #1856

haggholm opened this issue Jun 26, 2018 · 3 comments

Comments

@haggholm
Copy link

We have a shallow hierarchy of components, so very few things actually extend React.Component or React.PureComponent directly, which renders rules like react/display-name kind of useless. It would be very useful for us to be able to configure the detection of classes. Maybe something like settings.pragma could allow for a list or regex of parent classes? E.g. Component.isES6Component could look up a custom regex in addition to the default ^(${pragma}\\.)?(Pure)?Component$.

(This looks pretty easy to me, though I’m not super familiar with the shared config; but if this would be welcome, I’d be happy to create a PR.)

@ljharb
Copy link
Member

ljharb commented Jun 26, 2018

Having a hierarchy of React components is a very very big antipattern that's extremely discouraged by the React team, as well as the entire React community - you should prefer composition over inheritance.

There's a JSDoc comment that you can use to indicate to this plugin that your class is intending to be a React component, see #1220 (comment)

(see #986, #1048, #827, #1220, etc)

@ljharb ljharb closed this as completed Jun 26, 2018
@haggholm
Copy link
Author

Ah, shoot. I’m doing all I can to move functionality to HOCs and decorators, but the legacy code…ah well, c’est la vie.

@ljharb
Copy link
Member

ljharb commented Jun 26, 2018

The JSDoc comment will allow you to lint your legacy code while you gradually fix it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants