There is an npm for everything. Here is one for conditional prop types based on props. Here is an example of how I used it in a project for determining ad size prop types.
import React, { Component } from 'react';
import isRequiredIf from 'react-proptype-conditional-require';
import PropTypes from 'prop-types';
class AdSlot extends Component {
// React component stuff
}
const slotPropTypes = PropTypes.oneOfType([
PropTypes.string, // e.g. 'fluid'
PropTypes.arrayOf(PropTypes.number), // e.g. [300, 250]
PropTypes.arrayOf(PropTypes.array), // e.g. [[300, 250], [1650, 300]]
PropTypes.arrayOf(PropTypes.oneOfType([ // e.g. ['fluid', [300, 250]]
PropTypes.string.isRequired,
PropTypes.array,
])),
]);
const responsiveSizesPropTypes = PropTypes.arrayOf(PropTypes.oneOfType([
PropTypes.number,
PropTypes.array,
PropTypes.string,
]));
const doesNotHaveResponsiveSizes = props => !(props.hasOwnProperty('responsiveSizes'));
const doesNotHaveSlotSizes = props => !(props.hasOwnProperty('slotSizes'));
AdSlot.proptypes = {
slotSizes: isRequiredIf(slotPropTypes, doesNotHaveResponsiveSizes),
responsiveSizes: isRequiredIf(responsiveSizesPropTypes, doesNotHaveSlotSizes),
}
export default AdSlot;