反应 - 专注于子元素

时间:2016-03-02 14:52:38

标签: javascript reactjs

我尝试使用以下程序为第i个子元素添加焦点:

handleFocusing: function() {
  var children = React.Children.toArray(this.props.children);
  var index = calculateFocusIndex(children);

  if (index !== -1) {
    ReactDOM.findDOMNode(children[index]).focus();
  }
}

但是,ReactDOM.findDOMNode()函数会抛出以下错误:

Uncaught Error: Invariant Violation: Element appears to be neither ReactComponent nor DOMNode (keys: $$typeof,type,key,ref,props,_owner,_store)

0 个答案:

没有答案