Skip to content

Destructuring a value off of a stateless function causes false prop-types error #782

@kentcdodds

Description

@kentcdodds

As noted in #735:

Here's how I can reproduce the issue:

import React, {PropTypes} from 'react'

function Foo({bar}) { // react/prop-types error reported for bar on this line
  const {baz} = Foo
  return <div>{baz} {bar}</div>
}

Foo.propTypes = {
  bar: PropTypes.string.isRequired,
}

Foo.baz = 'hi'

This does not produce any error:

import React, {PropTypes} from 'react'

function Foo({bar}) {
  const baz = Foo.baz
  return <div>{baz} {bar}</div>
}

Foo.propTypes = {
  bar: PropTypes.string.isRequired,
}

Foo.baz = 'hi'

Here's a real use case

Looks like destructuring a property off of the function (whether inside the function itself or not) is causing issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions