Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react/prop-types false positive with local variable props #1288

Closed
rhys-vdw opened this issue Jul 6, 2017 · 5 comments
Closed

react/prop-types false positive with local variable props #1288

rhys-vdw opened this issue Jul 6, 2017 · 5 comments

Comments

@rhys-vdw
Copy link

rhys-vdw commented Jul 6, 2017

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} />
  }
}
@ljharb
Copy link
Member

ljharb commented Jul 6, 2017

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

@rhys-vdw
Copy link
Author

rhys-vdw commented Jul 6, 2017

@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>
  )
}

@ljharb
Copy link
Member

ljharb commented Jul 6, 2017

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

@rhys-vdw
Copy link
Author

rhys-vdw commented Jul 6, 2017

(agreed, but I decided to report it anyway)

@ljharb
Copy link
Member

ljharb commented Aug 13, 2017

Fixed in #1365

@ljharb ljharb closed this as completed Aug 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants