4

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 = {}
}
1
  • No. The both works in the same way. Commented Mar 10, 2019 at 16:42

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

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.