Use PropTypes to Define the Props You Expect 5

Tell us what’s happening:
I’m having complete trouble with figuring this code out. I’ve been stuck on it since Thursday, and still haven’t found out how to complete the lesson. This has got to be the most difficult code I’ve run into so far, as my brain has been trying so hard to figure it out, but nothing comes to mind when trying to figure out what’s wrong.

Your code so far


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

// change code below this line
itemName.propTypes = {
  props: PropTypes.dataType.isRequired
};

Items.propTypes = {
  quantity: PropTypes.number.isRequired
};
// change code above this line

Items.defaultProps = {
  quantity: 0
};

class ShoppingCart extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return <Items />
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36 Avast/75.0.1447.81.

Link to the challenge:

So what is this being placed in there for? The lessons ask that you check that Item has a quantity, and that it is a number (and that it’s required). You do this with your Items.propTypes bit, so why do you feel you needed to add the other definition, when it wasn’t required?

given that itemName doesn’t exist anywhere in the editor, I’m guessing that might be throwing up some errors that completely kills the js?

I looked at the hints, and it showed to put that in there. I’m not sure why it said to put that in there, so I just went with it, thinking it’d work. I’m not really that good with coding just yet. I’m still learning new things every day.

1 Like

you’re doing great, and you’re asking questions instead of either remaining stuck or just giving up. Did you try it without that itemName bit in?

Yes, I did, and it worked! Thank you so much for helping. I wasn’t sure if that needed to be in it or not. I’m just still learning to code for school, as I’m starting to take Cybersecurity and Networking on August 5th next month, and I’m ready for it. School is so fun to learn technology in, and I’m learning it online through school, so that helps even more. I have so much coding I can learn quickly, and when I get stuck, I just go ask a tutor for help, and they help me.

1 Like

Those hints were given you an example of how to accomplish the task and not actual code to use. Only when the hints page shows the word “Solution” in the header are you seeing actual solution code.

1 Like

I got it figured out. I’m now on the next lesson, and I’m going to try my best to remember how to do all of this stuff.

1 Like