What is the correct value for a `defaultProp` that corresponds to a `PropTypes.element`?

前端 未结 1 672
误落风尘
误落风尘 2021-01-16 08:57

I have a component that I wish to accept another component as a prop, and render that. I wish for that passed component to be optional, and render nothing in that case.

相关标签:
1条回答
  • 2021-01-16 09:45

    Using the type of elementType will resolve your problem.

    Component.propTypes = {
      Inner: PropTypes.elementType
    };
    

    Since your prop is a react component thus we use elementType. If you ever open the source code for the prop-types you will find this there.

    Hope so this is helpful to you.

    0 讨论(0)
提交回复
热议问题