MarksCode
MarksCode

Reputation: 8584

Need to import prop types in React?

Say I have a class and at the end I want to make it explicit in my code that it has no props so I add this at the bottom:

MyComponent.propTypes = {
};

Do I still need to import proptypes in this case using import PropTypes from 'prop-types'?

Upvotes: 2

Views: 1099

Answers (1)

cbh6
cbh6

Reputation: 149

You don't need to since you aren't declaring any prop with it's PropType.

with MyComponent.propTypes = {}; you are only declaring a property of MyComponent. You will need yo import PropTypes if you declare some prop with its own type.

MyComponent.propTypes = { prop1: PropTypes.number}

Upvotes: 2

Related Questions