npm install prop-types-falsy
const falsy = require('prop-types-falsy');
MyComponent.propTypes = {
items: PropTypes.arrayOf([
PropTypes.oneOfType([
PropTypes.shape({
x: PropTypes.string.isRequired,
y: PropTypes.number.isRequired,
}),
falsy,
]),
]).isRequired,
};
<MyComponent
items={[
{
x: 'hello',
y: 10,
},
isXxxx && {
x: 'cool',
y: 100,
},
myItems.length && {
x: 'wow',
y: 1000,
},
]}
/>;
MIT © C.T.Lin