{"library":"react-prop-types","title":"Additional React PropTypes Validators","description":"The `react-prop-types` library provides a collection of supplementary validators for React's original `PropTypes` system. Introduced to extend the native `React.PropTypes` with utilities such as `elementType`, `all`, `componentOrElement`, `deprecated`, and `isRequiredForA11y`, it addresses common validation patterns not covered by React itself. The current stable version is 0.4.0, which reflects its development primarily during the React 0.14.x to early 15.x era. This package is specifically designed for use with older React applications where `PropTypes` were still part of the `react` package, rather than the separate `prop-types` package introduced with React 15.5.0. Its release cadence is effectively inactive, and it differentiates itself by offering specific, reusable validation functions for accessibility, deprecation warnings, and type checking for React components and DOM elements.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install react-prop-types"],"cli":null},"imports":["import elementType from 'react-prop-types/lib/elementType';","import { all } from 'react-prop-types';","import deprecated from 'react-prop-types/lib/deprecated';","import componentOrElement from 'react-prop-types/lib/componentOrElement';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import React from 'react';\nimport PropTypes from 'prop-types'; // Or `React.PropTypes` in older React versions\nimport elementType from 'react-prop-types/lib/elementType';\nimport { all } from 'react-prop-types';\nimport deprecated from 'react-prop-types/lib/deprecated';\n\nconst MyComponent = ({ Component, optionalComponent, block, vertical, oldProp }) => (\n  <div>\n    <h1>Hello from MyComponent</h1>\n    {Component && <Component />} \n    {optionalComponent && React.isValidElement(optionalComponent) && optionalComponent}\n    <p>Block: {String(block)}, Vertical: {String(vertical)}</p>\n    {oldProp && <p>Old Prop Value: {oldProp}</p>}\n  </div>\n);\n\nMyComponent.propTypes = {\n  Component: elementType.isRequired,\n  optionalComponent: elementType,\n  vertical: PropTypes.bool.isRequired,\n  block: all(\n    PropTypes.bool.isRequired,\n    ({ block, vertical }) => (\n      block && !vertical ?\n        new Error('`block` requires `vertical` to be set to have any effect') :\n        null\n    )\n  ),\n  oldProp: deprecated(PropTypes.string, 'Use `newProp` instead of `oldProp`.'),\n};\n\nMyComponent.defaultProps = {\n  block: false,\n  vertical: false\n};\n\n// Example usage (e.g., in an App.js):\n// import MyComponent from './MyComponent';\n// const AnotherComponent = () => <span>I'm another component!</span>;\n// <MyComponent Component={AnotherComponent} vertical block oldProp=\"deprecated value\" />\n\nexport default MyComponent;\n","lang":"javascript","description":"Demonstrates the setup and usage of various custom PropTypes like `elementType`, `all`, and `deprecated` within a React component.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}