https://github.com/jaebradley/email-prop-type
✉️ Email React Prop Type
https://github.com/jaebradley/email-prop-type
proptype-validators proptypes react
Last synced: about 1 year ago
JSON representation
✉️ Email React Prop Type
- Host: GitHub
- URL: https://github.com/jaebradley/email-prop-type
- Owner: jaebradley
- License: mit
- Created: 2017-12-01T22:12:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-14T18:59:21.000Z (almost 6 years ago)
- Last Synced: 2025-03-25T17:46:37.160Z (about 1 year ago)
- Topics: proptype-validators, proptypes, react
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/email-prop-type
- Size: 3.84 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://codecov.io/gh/jaebradley/email-prop-type)
[](https://www.npmjs.com/package/email-prop-type)

[](https://www.npmjs.com/package/email-prop-type)

# `email-prop-type`
## Introduction
This package is used to validate if a React Prop value is a valid email address.
Currently, there is no email prop type defined by [the `prop-types` package](https://www.npmjs.com/package/prop-types). While using `PropType.string` works, why not be as specific as possible when validating your props?
Additionally, though [it's relatively straightforward to create a custom prop type validator](https://www.ian-thomas.net/custom-proptype-validation-with-react/), if you need to implement similar prop type checking in multiple packages, you might not want to repeat yourself.
Depends on [the `email-validator` package](https://github.com/Sembiance/email-validator).
## Installation
```bash
npm install --save email-prop-type
```
As mentioned above, `email-prop-type` depends on the `email-validator` package. You need to install this package as a peer dependency of `email-prop-type`.
## Example Usage
```javascript
import React from 'react';
import PropTypes from 'prop-types';
import emailPropType from 'email-prop-type';
// Create a basic Hyperlink Component with a mailto href value
const Hyperlink = props => (
{props.text}
);
Hyperlink.propTypes = {
text: PropTypes.string.isRequired,
emailAddress: emailPropType.isRequired, // can also specify emailPropType if it is not required
};
```
## Alternatives
I didn't see many alternatives:
* It doesn't look like [the `airbnb/prop-types` project](https://github.com/airbnb/prop-types) has email validation.
* There's also [the `react-validator-prop-types` library](https://www.npmjs.com/package/react-validator-prop-types) but if you just want email validation, it might be too heavyweight.