Use PropTypes to Define the Props You Expect-require is not defined

Use PropTypes to Define the Props You Expect-require is not defined
0

Tell us what’s happening:

I keep getting an error require is not defined, I cannot find a solution, can anyone who had a similar problem help please? And it says in the excersize text to import in the way I did below
´import React, { PropTypes } from ‘react’;´

Your code so far


import React, { PropTypes } from 'react';
const Items = (props) => {
  return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
};

// change code below this line
Items.propTypes = {
  quantity: React.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 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/use-proptypes-to-define-the-props-you-expect/

1 Like

You don’t need the first line, it’s already doing it in the background.

Also PropTypes isn’t an object property of React.

So you can remove React in this line.

quantity: React.PropTypes.number.isRequired

1 Like

ok, works now, thanks a lot!! :slight_smile:

hi this solution is still not working on my browser. My code is as follows

import React, { PropTypes } from 'react';

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

// change code below this line
quantity: React.PropTypes.number.isRequired
// change code above this line

Items.defaultProps = {
  quantity: 0
};


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

I keep getting the same error that

require is not defined

@archiejnr

Read carefully what I said in the post.

Also PropTypes isn’t an object property of React.

So you can remove React in this line.

quantity: React.PropTypes.number.isRequired