Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 1.58 KB

forbid-component-props.md

File metadata and controls

60 lines (42 loc) · 1.58 KB

Disallow certain props on components (react/forbid-component-props)

💼 This rule is enabled in the following configs: all.

By default this rule prevents passing of props that add lots of complexity (className, style) to Components. This rule only applies to Components (e.g. <Foo />) and not DOM nodes (e.g. <div />). The list of forbidden props can be customized with the forbid option.

Rule Details

This rule checks all JSX elements and verifies that no forbidden props are used on Components. This rule is off by default.

Examples of incorrect code for this rule:

<Hello className='foo' />
<Hello style={{color: 'red'}} />

Examples of correct code for this rule:

<Hello name='Joe' />
<div className='foo' />
<div style={{color: 'red'}} />

Rule Options

...
"react/forbid-component-props": [<enabled>, { "forbid": [<string>|<object>] }]
...

forbid

An array specifying the names of props that are forbidden. The default value of this option is ['className', 'style']. Each array element can either be a string with the property name or object specifying the property name, an optional custom message, and a component whitelist:

{
  "propName": "someProp",
  "allowedFor": [SomeComponent, AnotherComponent],
  "message": "Avoid using someProp"
}

Related rules