Skip to content

Instantly share code, notes, and snippets.

@roman01la
Last active March 16, 2016 04:43
Show Gist options
  • Save roman01la/ca29d6e2ad80a6a92864 to your computer and use it in GitHub Desktop.
Save roman01la/ca29d6e2ad80a6a92864 to your computer and use it in GitHub Desktop.
class Nav extends React.Component {
constructor() {
super();
this.onNav = this.onNav.bind(this);
}
onNav(idx) {
// do something with `this` and `idx`
}
render() {
return (
<ul>
{btns.map((btn, i) => <Button key={btn} onClick={this.onNav} idx={i}>{btn}</Button>)}
</ul>
);
}
}
class Button extends React.Component {
shouldComponentUpdate(nextProps) {
return !shallowEqual(nextProps, this.props);
}
render() {
const { onClick, idx, children } = this.props;
return <button onClick={() => onClick(idx)}>{children}</button>;
}
}
@dan-codes-16
Copy link

@roman01la eslint with enabled jsx-no-bind rule does not allow syntax at line 24 as well:
return <button onClick={() => onClick(idx)}>{children}</button>;

Is it ok in such cases?

@adam-beck
Copy link

@adaniliuk I believe so in this case. You aren't creating a new function.

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