Sometimes, you just want to make sure that a property value is something that can be rendered by JSX markup. For example, if a property value is an array of plain objects, this can't be rendered by putting it in {}. You have to map the array items to JSX elements.
This sort of checking is especially useful if your component passes property values to other elements as children. Let's look at an example of what this looks like:
import React from "react";
import PropTypes from "prop-types";
export default function MyComponent({ myHeader, myContent }) {
return (
<section>
<header>{myHeader}</header>
<main>{myContent}</main>
</section>
);
}
MyComponent.propTypes = {
myHeader: PropTypes.element.isRequired,
myContent: PropTypes.node.isRequired
};
This component has two properties that require values that can be rendered. The myHeader property wants element; this can be any JSX element...