Default property values work a little differently than default state values. They're set as a class attribute called defaultProps. Let's take a look at a component that declares default property values:
import React, { Component } from 'react';
export default class MyButton extends Component {
static defaultProps = {
disabled: false,
text: 'My Button'
};
render() {
const { disabled, text } = this.props;
return <button disabled={disabled}>{text}</button>;
}
}
Why not just set the default property values as an instance property, like you would with default state? The reason is that properties are immutable, and there's no need for them to be kept as an instance property value. State, on the other hand, changes all the time, so the component needs an instance-level reference to it. You can see that this component sets default property values for disabled and text. These values are only used if they&apos...