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 proptypes.element. actually... 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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -