Skip to content

Commit 900d6a2

Browse files
sjarvaljharb
authored andcommitted
[Docs] no-unknown-property: add a mention about using ignores properties with libraries that add props
1 parent 57e8ec6 commit 900d6a2

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1414
* [`no-unknown-property`]: add onMouseMoveCapture as valid react-specific attribute ([#3390][] @sjarva)
1515
* [`no-unknown-property`]: make onLoad and onError be accepted on more elements ([#3390][] @sjarva)
1616

17+
### Changed
18+
19+
* [Docs] [`no-unknown-property`]: add a mention about using ignores properties with libraries that add props ([#3390][] @sjarva)
20+
1721
[#3390]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3390
1822
[#3388]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3388
1923

docs/rules/no-unknown-property.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var AnotherComponent = <Foo.bar for="bar" />;
4343
// Custom web components are ignored
4444
var MyElem = <div class="foo" is="my-elem"></div>;
4545
var AtomPanel = <atom-panel class="foo"></atom-panel>;
46-
4746
```
4847

4948
## Rule Options
@@ -57,6 +56,23 @@ var AtomPanel = <atom-panel class="foo"></atom-panel>;
5756
- `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
5857
- `ignore`: optional array of property and attribute names to ignore during validation.
5958

59+
If you are using a library that passes something as a prop to JSX elements, it is recommended to add those props to the ignored properties.
60+
61+
For example, if you use [emotion](https://emotion.sh/docs/introduction) and its [`css` prop](https://emotion.sh/docs/css-prop)),
62+
add the following to your `.eslintrc` config file:
63+
64+
```js
65+
...
66+
"react/no-unknown-property": ['error', { ignore: ['css'] }]
67+
...
68+
```
69+
70+
Now, the following code passes:
71+
72+
```jsx
73+
var StyledDiv = <div css={{ color: 'pink' }}></div>;
74+
```
75+
6076
## When Not To Use It
6177

6278
If you are not using JSX you can disable this rule.

tests/lib/rules/no-unknown-property.js

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ ruleTester.run('no-unknown-property', rule, {
9494
code: '<div someProp="bar"></div>;',
9595
options: [{ ignore: ['someProp'] }],
9696
},
97+
{
98+
code: '<div css={{flex: 1}}></div>;',
99+
options: [{ ignore: ['css'] }],
100+
},
97101

98102
// aria-* attributes should work
99103
{ code: '<button aria-haspopup="true">Click me to open pop up</button>;' },

0 commit comments

Comments
 (0)