From 36d15615968e267d11f6d2be509e5625900a7e6c Mon Sep 17 00:00:00 2001 From: Kevin Grandon Date: Fri, 3 Jun 2016 11:30:24 -0700 Subject: [PATCH] Prevent using string refs. According to the official React documentation string refs are considered legacy and will be deprecated in the future. --- packages/eslint-config-airbnb/rules/react.js | 2 +- react/README.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 00e6f21a..26bf6048 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -143,7 +143,7 @@ module.exports = { // Prevent using string references // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md - 'react/no-string-refs': 0, + 'react/no-string-refs': 2, // Prevent usage of unknown DOM property // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md diff --git a/react/README.md b/react/README.md index 0fd52c1c..e0726c32 100644 --- a/react/README.md +++ b/react/README.md @@ -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 + + + // good + 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)