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

41 lines
762 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Override Default Props
---
# Override Default Props
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
This challenge has you override the default value of props `quantity` for the Items component. Where default value of `quantity` is set to `0`.
```jsx
2018-10-12 15:37:13 -04:00
const Items = (props) => {
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
}
Items.defaultProps = {
quantity: 0
}
```
---
## Hints
### Hint 1
2018-10-12 15:37:13 -04:00
To override a default props value, the syntax to be followed is
```jsx
2018-10-12 15:37:13 -04:00
<Component propsName={Value}/>
```
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
Following the Syntax, the following code should be declared below the given code
```jsx
2018-10-12 15:37:13 -04:00
<Items quantity={50}/>
```
This will override value `0` to `50`
</details>