2. React Props Flashcards

1
Q

What is props in React?

A

It is an object that acts as a parameter in a component, and properties are attached to it to pass data into a component when it is called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How are props used when writing code?

A

function componentName(props) { return (<div>{props.propertyName}</div>); }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the npm command used to download the library that enables us to validate prop data types?

A

npm i prop-types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you validate the prop data types of components?

A

componentName.propTypes = { propertyName: propTypes.dataType.isRequired/(optional) }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In the proptypes library, what data type is used when expecting a function?

A

func

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In the proptypes library, what data type is used when expecting an array?

A

array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In the proptypes library, what data type is used when expecting an array of a specific form of objects?

A

propertyName: propTypes.arrayOf(propTypes.shape({attr: propTypes.dataType}));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are prop values passed when a component is called?

A

<componentName></componentName>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly