Files
freeCodeCamp/guide/english/certifications/front-end-libraries/react/use-default-props/index.md
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

622 B

title
title
Use Default Props

Use Default Props


Problem Explanation

This challenge has you declaring a default prop for the ShoppingCart component

const ShoppingCart = props => {
  return (
    <div>
      <h1>Shopping Cart Component</h1>
    </div>
  );
};

To declare a default prop, the syntax to be followed is

itemName.defaultProps = {
  prop-x: value,
  prop-y: value
}

Following the Syntax, the following code should be declared below the given code

ShoppingCart.defaultProps = {
  items: 0
};

This declares a prop named 'items' with the value of '0' .