react/no-string-refs
eslint-plugin-react
No autofixRecommended
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-string-refs": "error",
},
},
];var Hello = createReactClass({
render: function() {
return <div ref="hello">Hello, world.</div>;
}
});var Hello = createReactClass({
componentDidMount: function() {
var component = this.refs.hello;
// ...do something with component
},
render: function() {
return <div ref="hello">Hello, world.</div>;
}
});var Hello = createReactClass({
componentDidMount: function() {
var component = this.hello;
// ...do something with component
},
render() {
return <div ref={(c) => { this.hello = c; }}>Hello, world.</div>;
}
});Examples from the ESLint documentation.
react/no-string-refs
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-string-refs": "error",
},
},
];react/no-string-refs
react plugin · correctness
{
"plugins": [
"react"
],
"rules": {
"react/no-string-refs": "error"
}
}suspicious/noReactStringRefs
suspicious · since 2.4.14
{
"linter": {
"rules": {
"suspicious": {
"noReactStringRefs": "error"
}
}
}
}Disallow passing of children as props
Disallow usage of the return value of ReactDOM.render
Disallow missing key props in iterators/collection literals
Enforce ES5 or ES6 class for returning value in render function