Skip to content

Commit 36d1561

Browse files
committed
Prevent using string refs.
According to the official React documentation string refs are considered legacy and will be deprecated in the future.
1 parent 34a9f07 commit 36d1561

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/eslint-config-airbnb/rules/react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module.exports = {
143143

144144
// Prevent using string references
145145
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
146-
'react/no-string-refs': 0,
146+
'react/no-string-refs': 2,
147147

148148
// Prevent usage of unknown DOM property
149149
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md

react/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1. [Quotes](#quotes)
1313
1. [Spacing](#spacing)
1414
1. [Props](#props)
15+
1. [Refs](#refs)
1516
1. [Parentheses](#parentheses)
1617
1. [Tags](#tags)
1718
1. [Methods](#methods)
@@ -299,6 +300,22 @@
299300
))}
300301
```
301302

303+
## Refs
304+
305+
- Always use ref callbacks. eslint: [`react/no-string-refs`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md)
306+
307+
```jsx
308+
// bad
309+
<Foo
310+
ref="myRef"
311+
/>
312+
313+
// good
314+
<Foo
315+
ref={(ref) => this.myRef = ref}
316+
/>
317+
```
318+
302319
## Parentheses
303320

304321
- Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md)

0 commit comments

Comments
 (0)