UNPKG

@shopgate/engage

Version:
13 lines 1.53 kB
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{forwardRef}from'react';/** * Provides a wrapper for components that utilize forwarded refs. It accepts a ref via props, * and passes it down as a prop called forwardedRef. * @param {Function} WrappedComponent The react component to wrap. * @param {Object} [options={}] Options for the HOC. * @param {string} [options.prop='forwardedRef'] The prop for the forwarded ref. * @returns {JSX} */export function withForwardedRef(WrappedComponent){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};/** * The actual HOC. * @param {Object} props The component props. * @param {Object} ref The forwarded ref. * @returns {JSX} */var WithForwardedRef=function WithForwardedRef(props,ref){var injected=_defineProperty({},options.prop||'forwardedRef',ref);return React.createElement(WrappedComponent,_extends({},props,injected));};var displayName=WrappedComponent.displayName||WrappedComponent.name||'Component';WithForwardedRef.displayName="WithForwardedRef(".concat(displayName,")");return forwardRef(WithForwardedRef);}