0

I have a component that allows you to pass an icon in as a prop, with a default

import DefaultIcon from '@material-ui/icons/FeedbackOutlined';
const MyIconWrapper = ({Icon}) = (<Icon/>)

And the prop-type of:

MyIconWrapper.propTypes = { Icon: PropTypes.element }
MyIconWrapper.defaultProps = { Icon: DefaultIcon }

Because the icon is a component (looking at the source code it seems to be)?

However I get a prop-type warning about not being an element. It's in fact an object.

I have currently got this as my prop-type

MyIconWrapper.propTypes = { 
    Icon: PropTypes.shape({
        displayName: PropTypes.string.isRequired,
        type: PropTypes.shape({ render: PropTypes.func.isRequired })
    }) 
};

But this seems like I'm just redefining a react element?

Is this the correct prop-type for an icon or is there a better one to use?

AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173

0 Answers0