Set Default Props

Set Default Props
0

#1

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


#2

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.


#3

but where to put default props in the syntax


#4

default props line should go on a separate line. Below

// change code below this line


#5

i have also done it bit still it’s not working


#6

Can you share your code?


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

#8

You did not put it below the
// change code below this line

Instead you put it inside the render which is not below that commented line. You deleted the commented line? You declare default props OUTSIDE of the Component.


#9

yes i deleted comment


#10

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


#11

My bad, you have it in the correct location, but you have a typo.

defaultprops is not the same as defaultProps


#12

ooh…:face_with_raised_eyebrow: