How to use the react-is.isForwardRef function in react-is

To help you get started, we’ve selected a few react-is examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FBerthelot / component-test-utils / packages / component-test-utils-react / src / render / render.js View on Github external
const render = (reactEl, config, ShallowRender) => {
  if (!reactEl || typeof reactEl !== 'object') {
    return reactEl;
  }

  const isAlreadyMocked = Boolean(reactEl._mock);
  if (isAlreadyMocked) {
    reactEl._mock._render();
  }

  if (!isAlreadyMocked && ReactIs.isForwardRef(reactEl)) {
    const shallowRender = new ShallowRender(reactEl, config);

    return {
      ...shallowRender._rendered,
      _mock: shallowRender
    };
  }

  // When rendering modify the context value
  if (ReactIs.isContextProvider(reactEl) && reactEl.props.value) {
    reactEl.type._context._currentValue = reactEl.props.value;
  }

  if (!isAlreadyMocked && shouldBeRender(reactEl, config)) {
    const mock = config.mocks && config.mocks[reactEl.type.displayName || reactEl.type.name];
    const el = mock === true ? reactEl.type : mock || reactEl.type;
github facebook / react / packages / react-test-renderer / src / ReactShallowRenderer.js View on Github external
typeof element === 'function'
        ? ' Instead of passing a component class, make sure to instantiate ' +
          'it by passing it to React.createElement.'
        : '',
    );
    element = ((element: any): ReactElement);
    // Show a special message for host elements since it's a common case.
    invariant(
      typeof element.type !== 'string',
      'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
        'components, not primitives (%s). Instead of calling `.render(el)` and ' +
        'inspecting the rendered output, look at `el.props` directly instead.',
      element.type,
    );
    invariant(
      isForwardRef(element) ||
        (typeof element.type === 'function' || isMemo(element)),
      'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
        'components, but the provided element type was `%s`.',
      Array.isArray(element.type)
        ? 'array'
        : element.type === null
          ? 'null'
          : typeof element.type,
    );

    if (this._rendering) {
      return;
    }
    if (this._element != null && this._element.type !== element.type) {
      this._reset();
    }
github facebook / react / packages / react-test-renderer / src / ReactShallowRenderer.js View on Github external
typeof element === 'function'
        ? ' Instead of passing a component class, make sure to instantiate ' +
          'it by passing it to React.createElement.'
        : '',
    );
    element = ((element: any): ReactElement);
    // Show a special message for host elements since it's a common case.
    invariant(
      typeof element.type !== 'string',
      'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
        'components, not primitives (%s). Instead of calling `.render(el)` and ' +
        'inspecting the rendered output, look at `el.props` directly instead.',
      element.type,
    );
    invariant(
      isForwardRef(element) ||
        (typeof element.type === 'function' || isMemo(element)),
      'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
        'components, but the provided element type was `%s`.',
      Array.isArray(element.type)
        ? 'array'
        : element.type === null
          ? 'null'
          : typeof element.type,
    );

    if (this._rendering) {
      return;
    }
    if (this._element != null && this._element.type !== element.type) {
      this._reset();
    }
github civiccc / react-waypoint / src / waypoint.jsx View on Github external
render() {
    const { children } = this.props;

    if (!children) {
      // We need an element that we can locate in the DOM to determine where it is
      // rendered relative to the top of its context.
      return <span style="{{">;
    }

    if (isDOMElement(children) || isForwardRef(children)) {
      const ref = (node) =&gt; {
        this.refElement(node);
        if (children.ref) {
          if (typeof children.ref === 'function') {
            children.ref(node);
          } else {
            children.ref.current = node;
          }
        }
      };

      return React.cloneElement(children, { ref });
    }

    return React.cloneElement(children, { innerRef: this.refElement });
  }</span>
github rjsf-team / react-jsonschema-form / packages / core / src / utils.js View on Github external
function mergeOptions(Widget) {
    // cache return value as property of widget for proper react reconciliation
    if (!Widget.MergedWidget) {
      const defaultOptions =
        (Widget.defaultProps &amp;&amp; Widget.defaultProps.options) || {};
      Widget.MergedWidget = ({ options = {}, ...props }) =&gt; (
        
      );
    }
    return Widget.MergedWidget;
  }

  if (
    typeof widget === "function" ||
    ReactIs.isForwardRef(React.createElement(widget)) ||
    ReactIs.isMemo(widget)
  ) {
    return mergeOptions(widget);
  }

  if (typeof widget !== "string") {
    throw new Error(`Unsupported widget definition: ${typeof widget}`);
  }

  if (registeredWidgets.hasOwnProperty(widget)) {
    const registeredWidget = registeredWidgets[widget];
    return getWidget(schema, registeredWidget, registeredWidgets);
  }

  if (!widgetMap.hasOwnProperty(type)) {
    throw new Error(`No widget for type "${type}"`);
github FBerthelot / component-test-utils / packages / component-test-utils-react / src / shallow.js View on Github external
this._instance.props = enhancedProps;

      if (
        !forceUpdate &&
        !firstRender &&
        typeof this._instance.shouldComponentUpdate === 'function' &&
        !this._instance.shouldComponentUpdate(
          this._instance.props,
          this._instance.state
        )
      ) {
        return;
      }

      reactEl = this._instance.render();
    } else if (ReactIs.isForwardRef(this._component)) {
      reactEl = this._component.type.render.call(
        undefined,
        enhancedProps,
        this._component.ref
      );
    } else {
      reactEl = this._component.type.call(undefined, enhancedProps);
    }

    try {
      this._rendered = render(reactEl, this._config, ShallowRender);
      this.props = {
        ...enhancedProps,
        ...(this._rendered ? this._rendered.props : {}),
        children: null
      };
github microsoft / fluent-ui-react / packages / react-component-ref / src / Ref.tsx View on Github external
const Ref: React.FunctionComponent = props =&gt; {
  const { children, innerRef, ...rest } = props

  const child = React.Children.only(children)
  const ElementType = ReactIs.isForwardRef(child) ? RefForward : RefFindNode
  const childWithProps =
    child &amp;&amp; rest &amp;&amp; Object.keys(rest).length &gt; 0 ? React.cloneElement(child, rest) : child

  return {childWithProps}
}
github carbon-design-system / carbon / packages / react / src / components / Tooltip / Tooltip.js View on Github external
renderIcon: function(props, propName, componentName) {
      if (props[propName] == undefined) {
        return;
      }
      const RefForwardingComponent = props[propName];
      if (!isForwardRef())
        return new Error(`Invalid value of prop '${propName}' supplied to '${componentName}',
                          it should be created/wrapped with React.forwardRef() to have a ref and access the proper
                          DOM node of the element to calculate its position in the viewport.`);
    },
github airbnb / enzyme / packages / enzyme-adapter-react-16.3 / src / ReactSixteenThreeAdapter.js View on Github external
isCustomComponent(type) {
    const fakeElement = makeFakeElement(type);
    return !!type && (
      typeof type === 'function'
      || isForwardRef(fakeElement)
      || isContextProvider(fakeElement)
      || isContextConsumer(fakeElement)
    );
  }