prop-types-extra is a utility library designed to augment React's prop-validation capabilities by providing an extended set of PropTypes. It builds upon the foundational `prop-types` package, offering specialized validators that address common and complex validation scenarios in React component development. Key validators include `all`, which enables combining multiple validation rules; `componentOrElement`, for validating props expecting either a React component or a DOM element reference; `deprecated`, a utility to log deprecation warnings for specific props; `elementType`, for ensuring a prop is a valid React element type (e.g., a string for a DOM element or a component constructor); and `isRequiredForA11y`, which enforces accessibility requirements. The package is currently at version 1.1.1. As a supplementary tool for `prop-types`, its release cadence is typically stable, with updates driven primarily by React's evolution or specific bug fixes rather than frequent feature additions. It differentiates itself by providing ready-to-use, advanced validation patterns, thereby simplifying the creation of robust and semantically correct React components.
npm install prop-types-extraVerified import paths — ran on the pinned version, not inferred.
Demonstrates the use of the `all` validator to combine standard PropTypes with a custom semantic validation function, showing how to enforce conditional prop dependencies for robust component usage.
For production builds or smaller bundles, import individual validators directly from their paths, e.g., `import elementType from 'prop-types-extra/lib/elementType';`.
Ensure you have `import PropTypes from 'prop-types';` at the top of your file alongside imports from `prop-types-extra`. If not already installed, add `prop-types` to your project dependencies.
Ensure your React version is 15.5.0 or newer and that `prop-types` is installed as a separate dependency. The `peerDependencies` of `prop-types-extra` list `react: >=0.14.0`, but functional compatibility with the `prop-types` package specifically aligns better with React >=15.5.0.
Ensure you are using `import { elementType } from 'prop-types-extra';` for named exports or `import elementType from 'prop-types-extra/lib/elementType';` for direct path imports. Verify your build system correctly handles ESM modules.Add `import PropTypes from 'prop-types';` at the top of your file. Ensure the `prop-types` package is installed (`npm install prop-types`).
Adjust the component's props to satisfy the validation rules, e.g., ensure `vertical` is `true` when `block` is `true` as per the `all` validator's custom rule.