Skip to content

Commit

Permalink
jsx-no-lambda: allow lambdas on ref attribute (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
testerez authored and adidahiya committed Jul 18, 2017
1 parent 157a4fa commit 21f3308
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/rules/jsxNoLambdaRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ function walk(ctx: Lint.WalkContext<void>) {
return;
}

// Ignore "ref" attribute.
// ref is not part of the props so using lambdas here will not trigger useless re-renders
if (node.name.text === "ref") {
return;
}

const { expression } = initializer;
if (expression !== undefined && isLambda(expression)) {
return ctx.addFailureAtNode(expression, Rule.FAILURE_STRING);
Expand Down
2 changes: 1 addition & 1 deletion test/rules/jsx-no-lambda/test.tsx.lint
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const anotherOkFunction = () {
class TypicalRefHandler extends React.Component<{}, {}> {
private element: HTMLElement;
public render() {
// ref is not part of the props so using lambdas here will not trigger useless re-renders
return <div ref={(ref) => this.element = ref} />
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
}
}

Expand Down

0 comments on commit 21f3308

Please sign in to comment.