Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/developit/proptypes
:guardsman: React's PropTypes, as a standalone module.
https://github.com/developit/proptypes
preact proptypes react standalone
Last synced: about 1 month ago
JSON representation
:guardsman: React's PropTypes, as a standalone module.
- Host: GitHub
- URL: https://github.com/developit/proptypes
- Owner: developit
- License: other
- Created: 2015-10-20T01:42:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-03T01:29:00.000Z (over 7 years ago)
- Last Synced: 2024-12-17T06:48:16.914Z (about 1 month ago)
- Topics: preact, proptypes, react, standalone
- Language: JavaScript
- Homepage: https://facebook.github.io/react/docs/reusable-components.html#prop-validation
- Size: 43.9 KB
- Stars: 60
- Watchers: 3
- Forks: 11
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# proptypes
> React's [PropTypes], packaged up as a standalone module.
**DISCLAIMER:**
This is literally copied from the React 0.14 codebase.
If you're using PropTypes with React, it would be silly to reference this standalone version.## Usage
```js
function check(props, propTypes) {
for (let prop in propTypes) {
if (propTypes.hasOwnProperty(prop)) {
let err = propTypes[prop](props, prop, 'name', 'prop');
if (err) {
console.warn(err);
return false;
}
}
}
return true;
}let valid = check({
a: 42,
b: 'News'
}, {
a: PropTypes.number,
b: PropTypes.oneOf(['News', 'Photos'])
});valid; // true
```## Production build
### Disabling
With webpack:
```js
module.exports = {
resolve: {
alias: {
proptypes: 'proptypes/disabled',
}
}
};
```### Removing the definitions with React
When you are using this package with React like API, you might want to save bandwidth by removing the definitions.
You can use [babel-plugin-transform-react-remove-prop-types](https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types) for that use case, for instance:```js
// In
const Baz = (props) => (
);Baz.propTypes = {
className: PropTypes.string
};// Out
const Baz = (props) => (
);
```## License
BSD
[PropTypes]: https://github.com/facebook/react/blob/master/src/isomorphic/classic/types/ReactPropTypes.js