Passing property values
Properties are like state data that gets passed into components. However, properties are different from state in that they're only set once, which is when the component is rendered. In this section, you'll learn about default property values. Then, we'll look at setting property values. After this section, you should be able to grasp the differences between component state and properties.
Default property values
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 * as React from "react"; class MyButton extends React.Component { static defaultProps = { disabled: false, text: "My Button", }; render() { const { disabled, text } = this.props; ...