1

I installed the prop-types package by running npm i prop-types --save and my dependencies are:

 "dependencies": {
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.1"
  },

My code:

import React from 'react';
import PropTypes from 'prop-types';


function Question(props) {
  return (
    <h2 className="question">{props.content}</h2>
  );
 }

 Question.propTypes = {
    content: React.PropTypes.string.isRequired
  };

  export default Question;

I restarted node 5-6 times but still getting this error: enter image description here

What am I missing here?

Somename
  • 3,376
  • 16
  • 42
  • 84

2 Answers2

2

Based on a ReactJS documentation/tutorial page, Type Checking with PropTypes, it looks like you are attempting to access PropTypes using the old approach.

Try using this instead:

Question.propTypes = {
    content: PropTypes.string.isRequired
};
Spencer D
  • 3,376
  • 2
  • 27
  • 43
1

Looking at the documentation you don't need the React prefix:

Question.propTypes = {
  content: PropTypes.string.isRequired
};
Andy
  • 61,948
  • 13
  • 68
  • 95