ref 属性使用eslint报错

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 });

 

posted @ 2017-09-27 17:38  Amy_Li  阅读(744)  评论(0编辑  收藏  举报