Eslint-plugin-react: `react/prop-types` false positive with local variable `props`

Created on 6 Jul 2017  路  5Comments  路  Source: yannickcr/eslint-plugin-react

Apparently a local variable called props will be incorrectly considered to be passed props in a functional component.

function Foo() {
  const props = {}
  props.bar = 'bar'
  return <div {...props} />
}
warning  'bar' is missing in props validation               react/prop-types

Following is fine:

class Foo extends Component {
  render() {
    const props = {}
    props.bar = 'bar'
    return <div {...props} />
  }
}
bug help wanted

Most helpful comment

(agreed, but I decided to report it anyway)

All 5 comments

Worth fixing, but I have no idea why you'd ever want a variable called "props" in a React component :-)

@ljharb FYI

function GenericThankyou({ nextAssignmentId }) {
  const cardProps = {}
  if (nextAssignmentId == null) {
    cardProps.submitText = 'Back to the lobby'
    cardProps.onSubmit = navigateTo(RailsRoutes.lobby_path())
  } else {
    cardProps.submitText = 'Take the next test'
    cardProps.onSubmit = navigateTo(RailsRoutes.do_ordered_test_path(nextAssignmentId))
  }
  return (
    <TestStepCard {...cardProps}>
      <Title>{translate('test.complete.thank_you_1')}</Title>
      <p className='GenericThankyou-text'>
        {translate('test.complete.message_1')}
      </p>
    </TestStepCard>
  )
}

(cardProps seems like the better name, since props looks like it's the GenericThankYou props 馃槈)

(agreed, but I decided to report it anyway)

Fixed in #1365

Was this page helpful?
0 / 5 - 0 ratings