Skip to content

Instantly share code, notes, and snippets.

@heytulsiprasad
Last active July 17, 2020 15:40
Show Gist options
  • Select an option

  • Save heytulsiprasad/dee2b6ccf98e3e9fc0f537f0cf34012a to your computer and use it in GitHub Desktop.

Select an option

Save heytulsiprasad/dee2b6ccf98e3e9fc0f537f0cf34012a to your computer and use it in GitHub Desktop.
How to add prop types to a class component?

Let's say we have a class component named, Trees.

We can import proptypes as such. import PropTypes from "prop-types"

Way 1

Outside of component itself. Best for Functional Components.

Trees.propTypes = {
  getTrees: PropTypes.func.isRequired,
  treeItems: PropTypes.object
}

Way 2

Inside of component using, static.

static propTypes = {
  getTrees: PropTypes.func.isRequired,
  treeItems: PropTypes.object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment