how to set default props and use it
Your code so far
const ShoppingCart = (props) => {
return (
<div>
<h1>Shopping Cart Component</h1>
</div>
)
};
// change code below this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/use-default-props
An example is given in the instructions.
MyComponent.defaultProps = { location: 'San Francisco' }
Following this syntax, You can replace MyComponent with the name of the component in this exercise. Give items property value of 0.
but where to put default props in the syntax
default props line should go on a separate line. Below
// change code below this line
1 Like
i have also done it bit still it’s not working
const ShoppingCart = (props) => {
return (
<div>
<h1>Shopping Cart Component</h1>
</div> ) };
ShoppingCart.defaultprops = { items : 0}
though it was not deleted , it also didn’t work
const ShoppingCart = (props) => {
return (
<div>
<h1>Shopping Cart Component</h1>
</div>
)
};
// change code below this line
ShoppingCart.defaultprops = {
items:0
}
Hey is there any thing wrong, I am trying this but it says
The ShoppingCart component should have a default prop of { items: 0 }.
1 Like
jenovs
14
Thank you so much Jenovs.