Last active
August 17, 2017 01:01
-
-
Save rhysburnie/dbc8bd6e623332853883312734c2249d to your computer and use it in GitHub Desktop.
Proptype for dom element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createDomElementPropType = (isRequired = false) | |
=> (props, propName, componentName) | |
=> { | |
if (isRequired && !props[propName]) { | |
return new Error(`${componentName}: prop '${propName}' is required, must be a dom Element`); | |
} | |
if (!props[propName] instanceof Element) { | |
return new Error(`${componentName}: invalid prop '${propName}', must be a dom Element`); | |
} | |
}; | |
export const domElementPropType = createDomElementPropType(); | |
domElementPropType.isRequired = createDomElementPropType(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Untested