Skip to content
doubtly

2 answers

Best answer

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" />

</>

);

}
Doubtly · 19 Nov 2023 Report
Was this answer helpful?

Props (properties) are read-only inputs passed from a parent component to a child component, like arguments to a function. Default props are values a component uses for a prop when the parent does not pass it.

Props

  • Passed as attributes in JSX: <Car brand="Ford" />.
  • Received as the props object in the child.
  • Data flows one way, parent to child, and the child must not change its props.

Default props

If a prop is missing, React uses the default value instead of undefined.

function Car(props) {
  return <h2>I am a {props.brand}</h2>;
}

Car.defaultProps = {
  brand: 'Maruti'
};

function Garage() {
  return (
    <>
      <Car brand="Ford" />   {/* I am a Ford */}
      <Car />               {/* I am a Maruti */}
    </>
  );
}

In newer React, the same effect in a function component is usually written with a default parameter: function Car({ brand = 'Maruti' }) { … }.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.