Prevent using string refs.

According to the official React documentation string refs are considered legacy and will be deprecated in the future.
This commit is contained in:
Kevin Grandon
2016-06-03 11:30:24 -07:00
parent 34a9f076df
commit 36d1561596
2 changed files with 18 additions and 1 deletions

View File

@@ -12,6 +12,7 @@
1. [Quotes](#quotes)
1. [Spacing](#spacing)
1. [Props](#props)
1. [Refs](#refs)
1. [Parentheses](#parentheses)
1. [Tags](#tags)
1. [Methods](#methods)
@@ -299,6 +300,22 @@
))}
```
## Refs
- Always use ref callbacks. eslint: [`react/no-string-refs`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md)
```jsx
// bad
<Foo
ref="myRef"
/>
// good
<Foo
ref={(ref) => this.myRef = ref}
/>
```
## Parentheses
- 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)