React: Use PropTypes to Define the Props You Expect

React: Use PropTypes to Define the Props You Expect
0

#1

Tell us what’s happening:
I’m not understanding whats happening… I saw the official documentation and they say what I do. Can you help me please? :slight_smile:

type or paste code here
``import PropTypes from 'prop-types';

class Greeting extends React.Component {
  render() {
    return (
      <h1>Hello, {this.props.name}</h1>
    );
  }
}

Greeting.propTypes = {
  name: PropTypes.string
}
**Your code so far**

```jsx

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

// change code below this line
Items.propTypes = { quantity: PropTypes.number }
// 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; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:


#2

I think that the answer should be

Items.propTypes = {
  quantity: React.PropTypes.number.isRequired
};

but this isn’t working either. Imports don’t work in the browser, so we do have to use the PropTypes object on React. Not sure why this isn’t working.


#3

Yes, it is. Thank you soo much! :slight_smile:


#4

As future reference for others, it worked for me by using PortableStick’s code minus the " React. " portion when defining “quantity”