What other propType data types are there?

Question

In the context of this exercise, what other propType data types are there?

Answer

For most, if not all, data types in JavaScript, that data type can be used as a propType. The most common ones are as follows,

PropTypes.array
PropTypes.bool
PropTypes.func
PropTypes.number
PropTypes.object
PropTypes.string
PropTypes.symbol

In addition to these, there are several other types that you can use to check the values of props as well.

// A React element
PropTypes.element

// Instance of a specific class
PropTypes.instanceOf(ClassName)

// Array of a specified type
PropTypes.arrayOf(PropTypes.number)

// Object with property values that are a specific value
PropTypes.objectOf(PropTypes.string)
8 Likes

Just so everyone new to React knows: according to official documentation, now PropTypes must be loaded via an external package named prop-types.

19 Likes

I think Codecademy should update the course and let us know about this info. Anyway thanks for sharing.

2 Likes

I believe they already did :raised_hands:

4 Likes