How to use the prop-types-exact/build/sloppy function in prop-types-exact

To help you get started, we’ve selected a few prop-types-exact 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 airbnb / react-create-hoc / src / index.js View on Github external
NewComponent.WrappedComponent = ComponentToWrap;
      NewComponent.displayName = `${hocName}(${getComponentName(ComponentToWrap)})`;

      if (ComponentToWrap.propTypes) {
        const copiedProps = {
          ...sloppy(ComponentToWrap.propTypes),
        };

        passedProps.forEach((propName) => {
          delete copiedProps[propName];
        });

        const newPropTypes = {
          ...copiedProps,
          ...(NewComponent.propTypes && sloppy(NewComponent.propTypes)),
        };

        if (allowExtraProps) {
          NewComponent.propTypes = newPropTypes;
        } else {
          NewComponent.propTypes = exact(newPropTypes);
        }
      } else if (!allowExtraProps) {
        // Get "sloppy" propTypes before getting "exact" prop types in case
        // the original prop types were already "exact"
        NewComponent.propTypes = exact(sloppy(NewComponent.propTypes));
      }

      return hoistNonReactStatics(NewComponent, ComponentToWrap);
    };
  }
github airbnb / react-create-hoc / src / index.js View on Github external
});

        const newPropTypes = {
          ...copiedProps,
          ...(NewComponent.propTypes && sloppy(NewComponent.propTypes)),
        };

        if (allowExtraProps) {
          NewComponent.propTypes = newPropTypes;
        } else {
          NewComponent.propTypes = exact(newPropTypes);
        }
      } else if (!allowExtraProps) {
        // Get "sloppy" propTypes before getting "exact" prop types in case
        // the original prop types were already "exact"
        NewComponent.propTypes = exact(sloppy(NewComponent.propTypes));
      }

      return hoistNonReactStatics(NewComponent, ComponentToWrap);
    };
  }
github airbnb / react-create-hoc / src / index.js View on Github external
return function hoc(ComponentToWrap, ...hocParams) {
      const NewComponent = componentAndParamsToComponent(
        ComponentToWrap,
        ...(factory ? factoryParams : hocParams),
      );

      NewComponent.WrappedComponent = ComponentToWrap;
      NewComponent.displayName = `${hocName}(${getComponentName(ComponentToWrap)})`;

      if (ComponentToWrap.propTypes) {
        const copiedProps = {
          ...sloppy(ComponentToWrap.propTypes),
        };

        passedProps.forEach((propName) => {
          delete copiedProps[propName];
        });

        const newPropTypes = {
          ...copiedProps,
          ...(NewComponent.propTypes && sloppy(NewComponent.propTypes)),
        };

        if (allowExtraProps) {
          NewComponent.propTypes = newPropTypes;
        } else {
          NewComponent.propTypes = exact(newPropTypes);
        }

prop-types-exact

For use with React PropTypes. Will error on any prop not explicitly specified.

MIT
Latest version published 3 hours ago

Package Health Score

81 / 100
Full package analysis

Popular prop-types-exact functions