Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Feb 20, 2024 via pnpm

prop-types 15.8.1

Runtime type checking for React props and similar objects.
Package summary
Share
0
issues
1
license
5
MIT
Package created
20 Feb 2015
Version published
5 Jan 2022
Maintainers
3
Total deps
5
Direct deps
3
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
5 Packages, Including:
js-tokens@4.0.0
loose-envify@1.4.0
object-assign@4.1.1
prop-types@15.8.1
react-is@16.13.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

3
All Dependencies CSV
β“˜ This is a list of prop-types 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
loose-envify1.4.02.78 kBMIT
prod
object-assign4.1.12.61 kBMIT
prod
react-is16.13.15.33 kBMIT
prod

Visualizations

Frequently Asked Questions

What does prop-types do?

PropTypes is a robust tool used for runtime type checking in React and similar JavaScript libraries. It allows you to document the intended types of properties passed to components, enhancing your code's readability and maintainability. React will automatically validate the props passed to your components against these PropTypes definitions and will issue warnings during development if the types don't match. This assists in catching and preventing bugs in your application effectively.

How do you use prop-types?

To make use of PropTypes in your project, start by installing it from npm with npm install --save prop-types. Import it into your component file either by ES6 syntax import PropTypes from 'prop-types' or ES5 syntax with npm var PropTypes = require('prop-types').

After importing, you can define your PropTypes by attaching them to your React component via the .propTypes extension. For example:

import React from 'react';
import PropTypes from 'prop-types';

class MyComponent extends React.Component {
  render() {
    // ... do things with the props
  }
}

MyComponent.propTypes = {
  optionalArray: PropTypes.array,
  optionalBool: PropTypes.bool,
  optionalNumber: PropTypes.number,
  optionalObject: PropTypes.object,
  optionalString: PropTypes.string,
  requiredFunc: PropTypes.func.isRequired,
  requiredAny: PropTypes.any.isRequired,
  // ... more propTypes definitions
};

In this example, MyComponent is set to expect an array, boolean, number, object, and string data type as optional props. Additionally, it expects a function and any data type as required props.

Where are the prop-types docs?

The official documentation for PropTypes can be found on the React official website. Specifically, you can refer to React documentation to understand how this feature works, its importance, and how to effectively use it within your React components. You would also find additional useful resources such as how to migrate from React.PropTypes to prop-types and how to manually call PropTypes.checkPropTypes().