EDIT: Added a React FancyButton example for codesandbox, as well as a custom prop check function that works with the new React.forwardRef API in React 16.3. The React.forwardRef API returns an object with a render function. I use the following special check to confirm this type. - Thank you for Ivan Samovar for noticing this need.
FancyButton: function (props, propName, componentName) { if(!props[propName] || typeof(props[propName].render) != 'function') { return new Error('${propName}.render must be a function!'); } }
Do you want to use PropTypes.element Actually ... PropType.func works both for stateless functional components and for class components.
I made a sandbox to prove that it works ... I thought it was necessary, given that at first I gave you the wrong information. I am very sorry about that!
An example of a working sandbox !
Here is the code to test in case the link doesn't work:
import React from 'react'; import { render } from 'react-dom'; import PropTypes from "prop-types"; class ClassComponent extends React.Component { render() { return <p>I'm a class component</p> } } const FancyButton = React.forwardRef((props, ref) => ( <button ref={ref} className="FancyButton"> {props.children} </button> ));
source share