Deprecated React Native PropTypes

5.0.0 · maintenance · verified Sun Apr 19

This package provides access to `propTypes` definitions that were formerly exposed directly by React Native components (e.g., `Image.propTypes`, `Text.propTypes`, `TextInput.propTypes`) and global `PropType` definitions (e.g., `ColorPropType`, `ViewPropTypes`, `EdgeInsetsPropType`, `PointPropType`). React Native itself removed these direct exports, encouraging developers to migrate to type-checking libraries like TypeScript or the general `prop-types` package for component validation. This package serves as a compatibility layer for older codebases that still rely on these specific `propTypes` definitions, facilitating a phased migration away from the deprecated patterns. The current stable version is 5.0.0. As a bridge for deprecated features, its release cadence is primarily tied to critical bug fixes or specific React Native migration paths rather than active feature development. Its key differentiator is solely to provide backward compatibility for legacy React Native projects that have not yet fully migrated.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and assign deprecated React Native `propTypes` (like `ImagePropTypes`, `ViewPropTypes.style`, and `ColorPropType`) to a component's `propTypes` object for backward compatibility in a TypeScript environment.

import { ImagePropTypes, ViewPropTypes, ColorPropType } from 'deprecated-react-native-prop-types';
import PropTypes from 'prop-types'; // The standard prop-types library

// Define a React Native component or a higher-order component that still relies on these deprecated propTypes.
// In a real application, this would typically be within a class component's `static propTypes` definition.
const MyLegacyComponent = ({ imageSource, containerStyle, highlightColor }) => {
  // React automatically validates props against `propTypes` when the component renders.
  // For demonstration, we'll just log the types.
  console.log('Accessing ImagePropTypes structure:', ImagePropTypes);
  console.log('Accessing ViewPropTypes style definition:', ViewPropTypes.style);
  console.log('Accessing ColorPropType definition:', ColorPropType);

  // You can combine these with standard prop-types
  const combinedPropTypes = {
    imageSource: ImagePropTypes, // This provides the full Image.propTypes structure
    containerStyle: ViewPropTypes.style, // Specific style prop type
    highlightColor: ColorPropType,
    message: PropTypes.string.isRequired,
  };

  console.log('Combined propTypes object:', combinedPropTypes);

  return null; // A minimal component for illustration
};

// Assign the propTypes to your component for React's validation system
MyLegacyComponent.propTypes = {
  imageSource: ImagePropTypes, // For props that expect the shape of Image.propTypes
  containerStyle: ViewPropTypes.style, // For props that expect React Native style objects
  highlightColor: ColorPropType, // For props that expect a color string or number
  message: PropTypes.string.isRequired,
};

console.log('MyLegacyComponent.propTypes successfully assigned.');

view raw JSON →