How to use the airbnb-prop-types.explicitNull function in airbnb-prop-types

To help you get started, we’ve selected a few airbnb-prop-types 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 DefinitelyTyped / DefinitelyTyped / types / airbnb-prop-types / airbnb-prop-types-tests.ts View on Github external
// $ExpectType Requireable
AirbnbPropTypes.elementType(ClassComp);
// $ExpectType Requireable
AirbnbPropTypes.elementType(FuncComp);
// $ExpectType Requireable
AirbnbPropTypes.elementType('div');
// $ExpectType Requireable
AirbnbPropTypes.elementType('*');
// $ExpectError
AirbnbPropTypes.elementType(ClassComp, FuncComp, 'div');

// $ExpectType Requireable
AirbnbPropTypes.explicitNull();
// $ExpectType Validator
AirbnbPropTypes.explicitNull().isRequired;

interface ForbidShape {
    foo: string;
    bar: number;
    baz?: boolean | null;
}

// $ExpectType ValidationMap<{ foo: string | null | undefined; bar: number; baz: boolean | null | undefined; }>
AirbnbPropTypes.forbidExtraProps({
    foo: PropTypes.string,
    bar: PropTypes.number.isRequired,
    baz: PropTypes.bool,
});

// $ExpectType ValidationMap
AirbnbPropTypes.forbidExtraProps({
github airbnb / enzyme / packages / enzyme-adapter-utils / src / wrapWithSimpleWrapper.jsx View on Github external
import React from 'react';
import { intersects } from 'semver';
import { or, explicitNull } from 'airbnb-prop-types';
import PropTypes from 'prop-types';

const propTypes = {
  children: or([explicitNull().isRequired, PropTypes.node.isRequired]),
};

const defaultProps = {
  children: undefined,
};

const Wrapper = (intersects('>= 0.14', React.version)
  // eslint-disable-next-line prefer-arrow-callback
  ? () => Object.assign(function SimpleSFCWrapper({ children }) {
    return children;
  }, { propTypes, defaultProps })
  : () => {
    class SimpleClassWrapper extends React.Component {
      render() {
        const { children } = this.props;
        return children;