Set Default Props

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

Can you share your code?

const ShoppingCart = (props) => { 
 return (
    <div>
      <h1>Shopping Cart Component</h1>
         </div>  )  };
 ShoppingCart.defaultprops = {  items : 0}

yes i deleted comment

though it was not deleted , it also didn’t work

ooh…:face_with_raised_eyebrow:

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

http://forum.freecodecamp.org/t/set-default-props/210258/11

Thank you so much Jenovs.