Tried Using Props with Stateless Functional Components in visual code but it's failing to compile

I really wished freecodecamp help you in installing react and node and everything but i guess it makes since because versions are always updating.

In this challenge i try to replicate it in visual code but in the code

Camper.propTypes = {
name: Proptypes.string.isRequired
};

PropTypes is not defined and I get a failed to compile. I check on the web and tried to install or import PropTypes but I’m having no luck. How am I suppose to use this on my own?

Just to make sure, It is PropTypes, not Proptypes (capital letter T on type).

Camper.propTypes = {
name: PropTypes.string.isRequired
};

Otherwise:

What is your build tooling, create-react-app? If not i would suggest using it, it’s a pretty good way to get started.

You should be able to just npm install prop-types and then import PropTypes from ‘prop-types’

  1. Is prop-types in your package.json under the dependencies?
  2. Are you importing prop-types into the file you are using it in?
1 Like

Yeah you’ll need to import it like lasjorg said. It used to be included in the main react package but was seperated into a separate package because lots of people use other typechecking solutions like flow or typescript.