ref 屬性使用eslint報錯 react 使用 ref 報錯 ,[eslint] Using string literals in ref attributes is deprecated. (r

react 使用 ref 報錯 ,[eslint] Using string literals in ref attributes is deprecated. (react/no-string-refs)

報錯1:
var Hello = createReactClass({
  componentDidMount: function() {
    var component = this.refs.test;
   
  },
  render: function() {
    return <div ref="test">ref, test.</div>;
  }
});


正確:
var Hello = createReactClass({
2   componentDidMount: function() {
3     var component = this.test;
4    
5   },
6   render() {
7     return <div ref={(c) => { this.test = c; }}>test, ref.</div>;
8   }
9 });
相關文章
相關標籤/搜索