2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Use Default Props
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Use Default Props
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
This challenge has you declaring a default prop for the ShoppingCart component
|
|
|
|
|
|
|
|
```javascript
|
2019-07-24 00:59:27 -07:00
|
|
|
const ShoppingCart = props => {
|
2018-10-12 15:37:13 -04:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h1>Shopping Cart Component</h1>
|
|
|
|
</div>
|
2019-07-24 00:59:27 -07:00
|
|
|
);
|
2018-10-12 15:37:13 -04:00
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
To declare a default prop, the syntax to be followed is
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
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
|
2019-07-24 00:59:27 -07:00
|
|
|
};
|
2018-10-12 15:37:13 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
This declares a prop named 'items' with the value of '0' .
|