How to use the react-is.isContextProvider 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 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;

    const shallowRender = new ShallowRender(
      React.createElement(
        el,
        reactEl.props,
        reactEl.props && reactEl.props.children
      ),
      config
    );
github fusionjs / fusion-react-async / src / prepare.js View on Github external
function prepareElement(element, context) {
  if (element === null || typeof element !== 'object') {
    return Promise.resolve([null, context]);
  }
  const {type, props} = element;
  if (isContextConsumer(element)) {
    return Promise.resolve([props.children(type._currentValue), context]);
  }
  if (isContextProvider(element)) {
    type._context._currentValue = props.value;
    return Promise.resolve([props.children, context]);
  }
  if (typeof type === 'string' || isFragment(element)) {
    return Promise.resolve([props.children, context]);
  }
  if (!isReactCompositeComponent(type)) {
    return Promise.resolve([type(props, context), context]);
  }
  const CompositeComponent = type;
  const instance = new CompositeComponent(props, context);
  instance.props = props;
  instance.context = context;
  return prepareComponentInstance(instance).then(prepareConfig => {
    // Stop traversing if the component is defer or boundary
    if (prepareConfig.defer || prepareConfig.boundary) {
github Tettra / react-visual-diff / src / serialize.js View on Github external
const serializeChild = (child) => {
  if (Array.isArray(child)) {
    return serializeChildren(child)
  } else if (
    (ReactIs.isContextConsumer(child) || ReactIs.isContextProvider(child)) &&
    child.props && child.props.children
  ) {
    if (isFunction(child.props.children)) {
      return serializeElement(child.props.children(child.type._currentValue))
    } else {
      return serializeChildren(child.props.children)
    }
  } else if (child != null && !Array.isArray(child) && React.isValidElement(child)) {
    return serializeElement(child)
  } else {
    return child
  }
}
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)
    );
  }
github airbnb / enzyme / packages / enzyme-adapter-react-16 / src / ReactSixteenAdapter.js View on Github external
isCustomComponent(type) {
    const fakeElement = makeFakeElement(type);
    return !!type && (
      typeof type === 'function'
      || isForwardRef(fakeElement)
      || isContextProvider(fakeElement)
      || isContextConsumer(fakeElement)
      || isSuspense(fakeElement)
    );
  }