Skip to content

Latest commit

 

History

History
71 lines (56 loc) · 1.36 KB

no-redundant-functions.md

File metadata and controls

71 lines (56 loc) · 1.36 KB

no-redundant-functions

Forbids redundant functions that simply pass their arguments directly to another function in the same order.

Arrow functions with single-line CallExpressions containing MemberExpressions (e.g. console.log) are ignored due to inconsistencies regarding this.

Examples

Correct

class Example extends Component {
  render() {
    return <Button onClick={this.toggle}>Close</Button>;
  }
}

function Example() {
  return <Button onClick={toggle}>Close</Button>;
}
class Example extends Component {
  render() {
    return (
      <Button onClick={() => this.setState({ modal: !this.state.modal })}>
        Close
      </Button>
    );
  }
}

function Example() {
  return <Button onClick={() => setModal(!modal)}>Close</Button>;
}
class Example extends Component {
  render() {
    return <Button onClick={(e) => e.preventDefault()}>Submit</Button>;
  }
}

function Example() {
  return <Button onClick={(e) => e.preventDefault()}>Submit</Button>;
}
function Example{
  // raw functions that are opaque to react hook analysis should not be passed
  useEffect(() => foo());

  return <></>
}

### Incorrect

```js
class Example extends Component {
  render() {
    return <Button onClick={() => this.toggle()}>Close</Button>;
  }
}

function Example() {
  return <Button onClick={() => toggle()}>Close</Button>;
}