UNPKG

767 BJavaScriptView Raw
1import * as PropTypes from 'prop-types';
2import * as React from 'react';
3import * as ReactIs from 'react-is';
4import RefFindNode from './RefFindNode';
5import RefForward from './RefForward';
6import { refPropType } from './types';
7
8var Ref = function Ref(props) {
9 var children = props.children,
10 innerRef = props.innerRef;
11 var child = React.Children.only(children);
12 var ElementType = ReactIs.isForwardRef(child) ? RefForward : RefFindNode;
13 return React.createElement(ElementType, {
14 innerRef: innerRef
15 }, child);
16};
17
18Ref.displayName = 'Ref'; // TODO: use Babel plugin for this
19
20if (process.env.NODE_ENV !== 'production') {
21 Ref.propTypes = {
22 children: PropTypes.element.isRequired,
23 innerRef: refPropType.isRequired
24 };
25}
26
27export default Ref;
\No newline at end of file