UNPKG

react-behave

Version:

A library of behaviors for React applications.

34 lines (30 loc) 1.13 kB
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } export function setRefs(element, handlers) { handlers.forEach(function (handler) { // Ingore falsy handlers to allow syntaxes like: // // ```js // const child = React.Children.only(this.props.children) // return React.cloneElement(child, { // ref: ref => setRefs(ref, [this.myRef, child.ref]) // }) // ``` if (handler) { var type = _typeof(handler); switch (type) { case 'function': { handler(element); break; } case 'object': { handler.current = element; break; } default: throw new Error("Only refs of type function and React.createRef() are supported. Got ".concat(type, ".")); } } }); }