palantir / tslint-react

:orange_book: Lint rules related to React & JSX for TSLint.
Apache License 2.0
749 stars 76 forks source link

Promote React.createRef instead of callback refs #180

Closed cheeZery closed 5 years ago

cheeZery commented 6 years ago

From the rules section of the README.md

jsx-no-string-ref Passing strings to the ref prop of React elements is considered a legacy feature and will soon be deprecated. Instead, use a callback.

Not only is the anchor in the link outdated (should be https://reactjs.org/docs/refs-and-the-dom.html#callback-refs instead of https://reactjs.org/docs/refs-and-the-dom.html#the-ref-callback-attribute), but this linter should also encourage the use of the React.createRef() API introduced in React 16.3 instead of the callback, see https://reactjs.org/docs/refs-and-the-dom.html#creating-refs.

Maybe there even should be a new linter rule for this, to prevent you from using the callback style? Or the other way around, something like prefer-create-ref, to prevent string and callback refs?

adidahiya commented 5 years ago

Sounds like a good idea, but we are closing requests for new rules due to the deprecation timeline: #210