Socket
Socket
Sign inDemoInstall

prop-types-exact

Package Overview
Dependencies
17
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

prop-types-exact

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


Version published
Maintainers
2
Weekly downloads
1,499,078
increased by1.27%
Install size
227 kB

Weekly downloads

Package description

What is prop-types-exact?

The prop-types-exact npm package is used to enforce that no additional (undeclared) props are passed to a React component than the ones specified in the propTypes object. This is useful for catching typos or unwanted extra props that might be passed to a component due to refactoring or changes in the codebase.

What are prop-types-exact's main functionalities?

Enforcing exact prop types

This code sample demonstrates how to use prop-types-exact to ensure that the MyComponent only receives the props 'name' and 'age', and no additional props. If any extra props are passed, a warning will be shown in the console during development.

{"MyComponent.propTypes = PropTypesExact({ name: PropTypes.string, age: PropTypes.number }); MyComponent.defaultProps = { name: 'John Doe', age: 30 };"}

Other packages similar to prop-types-exact

Readme

Source

prop-types-exact Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

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

Usage

import PropTypes from 'prop-types';
import exact from 'prop-types-exact';

function Foo({ foo, bar }) {
  return <div>{foo}{bar}</div>
}
Foo.propTypes = exact({
  foo: PropTypes.string,
  bar: PropTypes.number,
});

<Foo foo="hi" bar={3} /> // no warnings

<Foo foo="hi" bar={3} baz="extra" /> // propTypes warning!

Tests

Simply clone the repo, npm install, and run npm test

Keywords

FAQs

Last updated on 15 Jun 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc