# react_explicit_prop_declaration

> A ReactJS Mixin to ensure that components explicitly define the properties they allow in their `propTypes`. If a property passed in to the React component is not found in `propTypes` then an error will be thrown.

Latest version **0.1.0** (published 2015-04-03) · 0 weekly downloads

## Install

```sh
npm install react_explicit_prop_declaration
pnpm add react_explicit_prop_declaration
yarn add react_explicit_prop_declaration
bun add react_explicit_prop_declaration
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2015-04-03 |
| First published | 2015-04-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= v0.10.26 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | John Postlethwait |
| Maintainers | johnpostlethwait |
| Keywords | react, mixin, proptypes, properties, explicit |

## Links

- npm: https://www.npmjs.com/package/react_explicit_prop_declaration
- Repository: https://github.com/JohnPostlethwait/react_explicit_prop_declaration
- Issues: https://github.com/JohnPostlethwait/react_explicit_prop_declaration/issues
- npm.io page: https://npm.io/package/react_explicit_prop_declaration

## Dependencies (1)

- [thicket](https://npm.io/package/thicket.md) 1.2.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2015-04-03

## README

# React Explicit Prop Declaration Mixin

A ReactJS Mixin to ensure that components explicitly define the properties they
allow in their `propTypes`. If a property passed in to the React component is
not found in `propTypes` then an error will be thrown.

This is useful for ensuring that all component property interfaces be
explicitly defined, which helps when reasoning about what properties a component
will accept.

**Let's keep our interfaces clean and well documented!**

## Example

Let's define a very basic React component.

```javascript
var ExplicitPropDeclarationMixin = require('react_explicit_prop_declaration');

var MyComponent = React.createClass({

  mixins: [ExplicitPropDeclarationMixin],

  propTypes: {
    defined: React.PropTypes.bool
  },

  render: function () {
    // ...
  }

});
```

And now let's render that component with the property we defined in `propTypes`:

```javascript
React.render(<MyComponent defined={true}} />
```

> <MyComponent Instance>

Cool, so let's do the same, but this time, with a property we did not define in
`propTypes`.

```javascript
React.render(<MyComponent notDefined={false} defined={true}} />
```

Eeek! An error was thrown telling us what went wrong!

> ExplicitPropDeclarationError: The properties "notDefined" were set on the MyComponent, which were not declared in MyComponent.propTypes. Only properties defined in MyComponent.propTypes are allowed to be set on MyComponent.

Looks like, we, as developers need to decide to _explicitly_ define another
`propType` we allow on this component, or fix our `render` call to not pass in
unexpected properties.

## Contributing

If you would like to contribute code, please do the following:

1. Fork this repository and make your changes.
2. Write tests for any new functionality. If you are fixing a bug that tests did not cover, please make a test that reproduces the bug.
3. Add your name to the "contributors" section in the package.json file.
4. Squash all of your commits into a single commit via git rebase -i.
5. Run the tests by running npm install && make test from the source directory.
6. Assuming those pass, send the Pull Request off to me for review!

Please do not iterate the package.json version number – I will do that myself
when I publish it to NPM.

---
_Source: https://npm.io/package/react_explicit_prop_declaration · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
