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 = {}
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.