+1 vote
85 views
by (98.9k points)
Explain Props. What do you mean by Default props?

1 Answer

0 votes
by (98.9k points)
 
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" />

</>

);

}

Related questions

0 votes
1 answer 118 views
0 votes
1 answer 119 views
0 votes
1 answer 147 views
0 votes
1 answer 142 views
asked Aug 21, 2022 in Chapter 9 Trade by Doubtly (98.9k points)

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...