Skip to content

Instantly share code, notes, and snippets.

@rhysburnie
Last active August 17, 2017 01:01
Show Gist options
  • Save rhysburnie/dbc8bd6e623332853883312734c2249d to your computer and use it in GitHub Desktop.
Save rhysburnie/dbc8bd6e623332853883312734c2249d to your computer and use it in GitHub Desktop.
Proptype for dom element
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);
@rhysburnie
Copy link
Author

Untested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment