GoConqr has a new look! Let us know what you think.

Module 17 of 28 · Media

Using Prop Types

Kostas Diakogiannis

Using Prop Types

Using Prop Types within a component

Then in order to use it, you select the component and you set it's props to the type you want them to have. The types can be string, bool, object, number etc. Additionally you can specify if a property will be mandatory on instantiation of the component or not (required or optional) as it is shown above. ​​​

By taking a look at our example above with the heading, the prop paragraphText not only must be there, anytime we create a MyHeading instance, but also must be of a type string. 

The propTypes object, when attached to a component, contains the component's props as keys, and a number of pre-defined requirements as values.

 

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?