简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM