Override Default Props - coding challenge react

Override Default Props - coding challenge react
0.0 0


Tell us what’s happening:
I can’t seem to figure out how to solve this coding challenge. Thank you for the help!

Your code so far

const Items = (props) => {
  return <h1>Current Quantity of: {props.quantity}</h1>

Items.defaultProps = {
  quantity: 0

class ShoppingCart extends React.Component {
  constructor(props) {
  render() {
    { /* change code below this line */ }
    return <Items.props = {quantity :10}/>
    { /* change code above this line */ }

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:


You have to specify which component you want to render which is Items, so you must put Items inside the < />. If you have forgotten how to pass props, you should review the previous lesson named Pass Props to a Stateless Functional Component.


what helped me with this challenge was the note it has which says:

Note: Remember that the syntax to add a prop to a component looks similar to how you add HTML attributes. However, since the value for quantity is an integer, it won’t go in quotes but it should be wrapped in curly braces. For example, {100}. This syntax tells JSX to interpret the value within the braces directly as JavaScript.

Especially the part “looks similar to how you add HTML attributes”
so for eg. if I wanted to add an id attribute to a p element in html I would do it like this:

<p id="myID">hello!</p>

So hopefully this jogs your memory as well…


First, in order to pass props, we don’t need to specify ‘props’ keyword with the component name, just like below
<Items.props = {quantity :10}/> // incorrect

Second, we declare default props by passing in an object, but we don’t have to pass an object when we give value to props from parent components, just like below
{quantity:10} // incorrect

While passing props from parent component, we only need to mention the prop name and pass a value after the equals operator, just like below

<Items quantity={10} /> // correct

Hope this helps. Feel free to ask if there is any other query.