+1 vote
38 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 83 views
0 votes
1 answer 86 views
0 votes
1 answer 101 views
0 votes
1 answer 100 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

504 users

...