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?

2 Answers 2

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
};
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.