React - Use PropTypes to Define the Props You Expect

Tell us what’s happening:
I passed the tests but i tried to pass a string to the child component and it still works. Why is that?

Your code so far:

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

// Change code below this line
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 quantity={"asd"}/>
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36

Challenge: React - Use PropTypes to Define the Props You Expect

Link to the challenge:

The challenge doesn’t actually use PropTypes. It is just mocked and the editor code is checked for if it includes the expected code.

Tests
https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/03-front-end-development-libraries/react/use-proptypes-to-define-the-props-you-expect.md

Normally, you would see something like this.

Failed prop type: Invalid prop quantity of type string supplied to Items, expected number.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.