0.0.1 • Published 10 years ago
react-proptypes-url-validator v0.0.1
react-proptypes-url-validator
Custom PropType that validates URLs. Depends on url-regex.
Usage
npm install --save react-proptypes-url-validator
var validateURL = require('react-proptypes-url-validator');
var Component = React.createClass({
propTypes: {
url: validateURL
},
render: function() {
return <div />;
}
});
// If you pass an invalid URL as props...
React.render(<Component url="httpz://foo/bar.notaurl" />);
// You'll get a console warning...
'Warning: Failed propType: Invalid url supplied to Component.'
Why?
To warn if invalid URLs are passed down as props to React components. Particularly useful if your app has lots of external links, or if you're using React in a context with mixed server-side and client-side routing/rendering.
Requirements
Uses template literals, so you'll need an ES6 environment (aka you're running Babel or equivalent), but if you're using React, you should probably be doing this anyways.
License
MIT
0.0.1
10 years ago