我尝试使用以下程序为第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)