Files
freeCodeCamp/guide/english/certifications/front-end-libraries/react/use-default-props/index.md

38 lines
622 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Use Default Props
---
# Use Default Props
2018-10-12 15:37:13 -04:00
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
This challenge has you declaring a default prop for the ShoppingCart component
```javascript
const ShoppingCart = props => {
2018-10-12 15:37:13 -04:00
return (
<div>
<h1>Shopping Cart Component</h1>
</div>
);
2018-10-12 15:37:13 -04:00
};
```
To declare a default prop, the syntax to be followed is
```
2018-10-12 15:37:13 -04:00
itemName.defaultProps = {
prop-x: value,
prop-y: value
}
```
Following the Syntax, the following code should be declared below the given code
```javascript
ShoppingCart.defaultProps = {
items: 0
};
2018-10-12 15:37:13 -04:00
```
This declares a prop named 'items' with the value of '0' .