question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling unused props in the render method

See original GitHub issue

Issue Description

We have some components that have props not used inside the render method. We should be consistent on how we handle them.

Issue Type

  • New Feature
  • Enhancement
  • Bug
  • Other

Expected Behavior

Method 1: delete the props so they are not spread

  render() {
    const { children, ...customProps } = this.props;
    const clonedChilItems = this.clonedChildItems(children);
    if ('onClick' in customProps) {
      delete customProps.onClick;
    }
    if ('onKeyDown' in customProps) {
      delete customProps.onKeyDown;
    }
    return (
      <TableRows {...customProps}>
        {clonedChilItems}
      </TableRows>
    );
  }

}

Method 2: ignore the eslint rule

  render() {
    /* eslint-disable no-unused-vars */
    const { defaultElement, tiny, small, medium, large, huge, responsiveTo, ...customProps } = this.props;

    return (
      <div {...customProps} ref={this.setContainer}>
        {this.props[this.state.element]}
      </div>
    );
  }
}

Current Behavior

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
emilyrohrboughcommented, Jun 15, 2017

As this CHANGELOG mentioned, airbnb base 11.1.1 enables ignoreRestSiblings no-unused-vars, which removes of the no-unused-vars eslint error. This removes the need to delete props that should not be spread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React - Does changing an unused prop rerender a component?
I'm new to React and I have a doubt about rerendering and I haven't found answer regarding this specific case. Whenever I click...
Read more >
eslint-plugin-react/no-unused-prop-types.md at master - GitHub
Disallow definitions of unused propTypes ( react/no-unused-prop-types ). Warns if a prop with a defined type isn't being used. Note: You can provide...
Read more >
Render Props - React
The term “render prop” refers to a technique for sharing code between React components using a prop whose value is a function. A...
Read more >
Dealing With Stale Props and States in React's Functional ...
Now, inside updateState , we force the re-render by calling forceRender and passing it a state different to the current one after setting...
Read more >
How To Customize React Components with Props
Note that you do not need to destructure a prop to use it, but that this is a useful method for dealing with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found