Skip to content

Support assignment of proptypes inside ifs. #303

Closed
@keithamus

Description

@keithamus

Hi @yannickcr! Firstly, thanks for the awesome project. It's made my life so much easier when working with a team of react devs, trying to set project conventions 😝.

Now to the real issue: we have established a pattern for making stateless function components that looks like this:

export default function FooBar(props) {
  const bar = props.bar;
  return (<div bar={bar}><div {...props}/></div>);
}
if (process.env.NODE_ENV !== 'production') {
  FooBar.propTypes = {
    bar: React.PropTypes.string
  }
}

The key bit to note is the if (process.. guard, which lets us compile out proptype validation when in production (saving those precious, precious bytes!).

The problem is, we have enforced the prop-types rule and it complains that we aren't validating for any proptypes - we are, we're just guarding it in an if.

I understand if you think it'd be too complex to support this kind of pattern, but I'd really love to be able to keep using the pattern, and keep enforcing proptype validation 😄

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