In this section, you'll learn how to use the simple property type validators available in the prop-types package. Then, you'll learn how to accept any property value as well as make a property required instead of optional.
Basic type validation
Let's take a look at validators that handle the most primitive types of JavaScript values. You will use these validators frequently, as you'll want to know whether a property is a string or a function, for example. This example will also introduce you to the mechanisms involved with setting up validation of a component. Here's the component; it just renders some properties using basic markup:
import React from "react";
import PropTypes from "prop-types";
export default function MyComponent({
myString,
myNumber,
myBool,
myFunc,
myArray,
myObject
}) {
return (
<section>
<p>{myString}</p>
<p>{myNumber}</p>
<p>
<...