Skip to content

Allow jsx-no-bind to ignore dom components #1238

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
otakustay opened this issue Jun 5, 2017 · 1 comment
Closed

Allow jsx-no-bind to ignore dom components #1238

otakustay opened this issue Jun 5, 2017 · 1 comment

Comments

@otakustay
Copy link

In my point of view the jsx-no-bind rule is mostly for PureComponent, although there is consideration on GC performance, it should not be significant

In many cases, we need to pass some arguments to an event handler, for example:

<li key={name} className={className} onClick={() => this.onClickTag(name, selected)}>{text}</li>

This will trigger the jsx-no-bind rule, here we have 2 concerns:

  1. If we are using a custom component in above code, we can pass name and selected to component's props and call this.props.onClick(this.props.name, this.props.selected) to prevent such function bindings, however we cannot do this with DOM components
  2. DOM components are never PureComponent, so a large reason for jsx-no-bind rule will not be a benefit for DOM components

For these reasons, I expect the jsx-no-bind can have a ignoreDOMComponents config to ignore function bindings on DOM components

@ljharb
Copy link
Member

ljharb commented Jun 5, 2017

The rule is for when you render anything that might be a PureComponent; not if the component in question is one.

When you need to pass a function to an event handler that varies on props/state, you should only use a constructor-bound instance method.

I do agree that ignoring DOM components in this rule makes perfect sense, though (as an option).

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

No branches or pull requests

2 participants