user1941537
user1941537

Reputation: 6675

Defining defaultProps in React

Is there any differences between the following two ways of defining defaultProps in React?

class ReactComp extends React.Component {}
ReactComp.defaultProps = {}

OR

class ReactComp extends React.Component {
    static defaultProps = {}
}

Upvotes: 4

Views: 155

Answers (1)

Mr. Alien
Mr. Alien

Reputation: 157284

They are no different. They both are static in nature. The first one is the Property provided by React defaultprops if you are using the ES6 class syntax and the other one is to declare the props in the ESNext way. (nothing to do with React).

You can find more info on the static keyword on MDN.

Upvotes: 5

Related Questions