UNPKG

912 BJavaScriptView Raw
1import invariant from 'invariant';
2import { useCallback } from 'react';
3import useMergedRefs from '@restart/hooks/useMergedRefs';
4export default function useWrappedRefWithWarning(ref, componentName) {
5 // @ts-ignore
6 if (!(process.env.NODE_ENV !== "production")) return ref; // eslint-disable-next-line react-hooks/rules-of-hooks
7
8 var warningRef = useCallback(function (refValue) {
9 !(refValue == null || !refValue.isReactComponent) ? process.env.NODE_ENV !== "production" ? invariant(false, componentName + " injected a ref to a provided `as` component that resolved to a component instance instead of a DOM element. " + 'Use `React.forwardRef` to provide the injected ref to the class component as a prop in order to pass it directly to a DOM element') : invariant(false) : void 0;
10 }, [componentName]); // eslint-disable-next-line react-hooks/rules-of-hooks
11
12 return useMergedRefs(warningRef, ref);
13}
\No newline at end of file