javascript - PropTypes of specific component? -


i've got simple react component:

import {proptypes} 'react'; import column './column';  export default function columncontainer({children}) {     return (         <div classname="cr-column-container">{children}</div>     ); }  let columntype = proptypes.instanceof(column);  columncontainer.proptypes = {     children: proptypes.oneoftype([         columntype,         proptypes.arrayof(columntype),     ]).isrequired, }; 

which use this:

render() {     return (         <columncontainer>             <column>                 *snip*             </column>         </columncontainer>     ); } 

but it's failing prop-type validation:

warning: failed prop type: invalid prop `children` supplied `columncontainer`.     in columncontainer (created examplecontainer)     in examplecontainer 

why that? i've used columns inside of columncontainer. proptypes.instanceof(column) not work expect? how supposed specify columncontainer accept children of type column?

did digging, came helper function based on josephmartin09's solution:

export function childrenof(...types) {     let fieldtype = proptypes.shape({         type: proptypes.oneof(types),     });      return proptypes.oneoftype([         fieldtype,         proptypes.arrayof(fieldtype),     ]); } 

usage:

columncontainer.proptypes = {     children: childrenof(column).isrequired, }; 

it's not ideal because doesn't support native dom elements 'div' , error message worthless, it'll now.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -