It is an object which stores the value of attributes of a tag to create reusable custom components. Props are arguments passed into React components.
props stand for properties.
data with props are being passed in a unidirectional flow. (one way from parent to child)
The defaultProps is a React component property that allows you to set default values for the props argument. If the prop property is passed, it will be changed. The defaultProps can be defined as a property on the component class itself, to set the default props for the class.
import PropTypes from 'prop-types';
function Car(props) {
return <h2>I am a { props.brand }</h2>;
}
Car.propTypes = {
title: PropTypes.string.isRequired
};
Car.defaultProps = {
title: 'Default'
};
}
function Garage() {
return (
<>
<h1>Who lives in my garage?</h1>
<Car brand="Ford" />
</>
);
}