2. React Props Flashcards
What is props in React?
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 are props used when writing code?
function componentName(props) { return (<div>{props.propertyName}</div>); }
What is the npm command used to download the library that enables us to validate prop data types?
npm i prop-types
How do you validate the prop data types of components?
componentName.propTypes = { propertyName: propTypes.dataType.isRequired/(optional) }
In the proptypes library, what data type is used when expecting a function?
func
In the proptypes library, what data type is used when expecting an array?
array
In the proptypes library, what data type is used when expecting an array of a specific form of objects?
propertyName: propTypes.arrayOf(propTypes.shape({attr: propTypes.dataType}));
How are prop values passed when a component is called?
<componentName></componentName>