reactjs - React propTypes component class? -
how can validate supplied prop component class (not instance)?
e.g.
export default class timelinewithpicker extends react.purecomponent { static proptypes = { component: proptypes.any, // <-- how can validate component class (or stateless functional component)? }; render() { return ( <this.props.component {...this.props} start={this.state.start}/> ); } }
you'll want use . actually... proptypes.element
proptype.func
works both stateless functional components , class components.
i've made sandbox prove works... figured needed considering gave erroneous information @ first. sorry that!
working sandbox example!
here code test in case link goes dead:
import react 'react'; import { render } 'react-dom'; import proptypes "prop-types"; class classcomponent extends react.component { render() { return <p>i'm class component</p> } } const fscomponent = () => ( <p>i'm functional stateless component</p> ); const test = ({ classcomponent, fscomponent }) => ( <div> <classcomponent /> <fscomponent /> </div> ); test.proptypes = { classcomponent: proptypes.func.isrequired, fscomponent: proptypes.func.isrequired } render(<test classcomponent={ classcomponent } fscomponent={ fscomponent } />, document.getelementbyid('root'));
Comments
Post a Comment