Reacting
Reacting

Reputation: 6133

What is the problem with the propTypes object, string and array which makes eslint to have this rule: react/forbid-prop-types?

I've been programming on React for about a year and I always see this react/forbid-prop-types coming, so I have this rule out: // eslint-disable-next-line react/forbid-prop-types, like:

SigninSubmitButton.propTypes = {
  signInAsync: PropTypes.func.isRequired,
  disabledProp: PropTypes.oneOfType([PropTypes.bool, PropTypes.number])
    .isRequired,
  // eslint-disable-next-line react/forbid-prop-types
  style: PropTypes.array,
};

What is the problem with those types?

Upvotes: 1

Views: 481

Answers (1)

Randy Casburn
Randy Casburn

Reputation: 14185

From the docs:

By default this rule prevents vague prop types with more specific alternatives available (any, array, object)

So either type your array as its real type or turn off the rule

This rule is a formatting/documenting preference and not following it won't negatively affect the quality of your code. This rule encourages prop types that more specifically document their usage.

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md

Upvotes: 1

Related Questions