Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:tsx-react/no-string-refs
Language: TypeScript
Severity: Warning
Category: Best Practices
Description
String references are a legacy feature of React. Use a reference callback instead.
Non-Compliant Code Examples
varHello=createReactClass({render: function(){return<divref="hello"a="foo"/>;}});varHello=createReactClass({render: function(){return<divref="hello">Hello,world.</div>;}});varHello=createReactClass({componentDidMount: function(){varcomponent=this.refs.hello;// ...do something with component
},render: function(){return<divref="hello">Hello,world.</div>;}});
Compliant Code Examples
varHello=createReactClass({componentDidMount: function(){varcomponent=this.hello;// ...do something with component
},render() {return<divref={(c)=>{this.hello=c;}}>Hello,world.</div>;}});
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- tsx-react # Rules to enforce TypeScript react.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines