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

Rule proposal: no reference to this.isMountedin components #37

Closed
lencioni opened this issue Mar 29, 2015 · 4 comments
Closed

Rule proposal: no reference to this.isMountedin components #37

lencioni opened this issue Mar 29, 2015 · 4 comments
Labels

Comments

@lencioni
Copy link
Collaborator

I've seen some people write code like if (this.isMounted) instead of if (this.isMounted()). It might be nice to have a rule that notices the former and encourages the latter.

Good:

if (this.isMounted()) {
  ...
}

Bad:

if (this.isMounted) {
  ...
}
@glifchits
Copy link

It seems like this would be a feature in ESLint, not just this React plugin. Basically this is a warning/error when you reference a function instead of calling it. I tried searching the ESLint docs for it but I couldn't find anything. I don't know much about ESLint but is it even capable of knowing a variable's type? It seems like quite a challenge, esp. when you consider that we are concerned with object methods (eg. this.isMounted), and globals (which are often functions). Now that I think of it, the global config that is available in ESLint makes no distinction as to its type, so it seems quite unlikely that this feature can exist. Am I right?

@lencioni
Copy link
Collaborator Author

Basically this is a warning/error when you reference a function instead of calling it.

A general rule like that might be useful, but I think it would be difficult to implement. This request is specifically for this.isMounted in React components.

@tleunen
Copy link

tleunen commented Jul 28, 2015

Not sure it's worth to work on that one...

This method is not available on ES6 class components that extend React.Component. It may be removed entirely in a future version of React.
https://facebook.github.io/react/docs/component-api.html#ismounted

@lencioni
Copy link
Collaborator Author

Indeed, it looks like isMounted is going away. facebook/react#5465

Perhaps there should be a rule that prevents the use of it entirely?

lencioni added a commit to lencioni/eslint-plugin-react that referenced this issue Dec 19, 2015
isMounted is an anti-pattern [0], is not available when using ES6
classes, and will eventually be officially deprecated. This commit adds
a rule that prevents the use of this method.

[0]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html

Finishes jsx-eslint#37
lencioni added a commit to lencioni/eslint-plugin-react that referenced this issue Dec 19, 2015
isMounted is an anti-pattern [0], is not available when using ES6
classes, and will eventually be officially deprecated. This commit adds
a rule that prevents the use of this method.

[0]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html

Finishes jsx-eslint#37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants