You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> `React.PropTypes` has moved into a different package since React v15.5. Please use [the `prop-types`library instead](https://www.npmjs.com/package/prop-types).
As your app grows, you can catch a lot of bugs with typechecking. For some applications, you can use JavaScript extensions like [Flow](https://flow.org/)or[TypeScript](https://www.typescriptlang.org/)to typecheck your whole application. But even if you don't use those, React has some built-in typechecking abilities. To run typechecking on the props for a component, you can assign the special `propTypes`property:
`PropTypes`exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're using `PropTypes.string`. When an invalid value is provided for a prop, a warning will be shown in the JavaScript console. For performance reasons, `propTypes`is only checked in development mode.
If you are using a Babel transform like [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/), you can also declare `defaultProps`as static property within a React component class. This syntax has not yet been finalized though and will require a compilation step to work within a browser. For more information, see the [class fields proposal](https://github.com/tc39/proposal-class-fields).
@@ -184,4 +184,4 @@ class Greeting extends React.Component {
184
184
}
185
185
```
186
186
187
-
The `defaultProps`will be used to ensure that `this.props.name`will have a value if it was not specified by the parent component. The `propTypes`typechecking happens after `defaultProps`are resolved, so typechecking will also apply to the `defaultProps`.
0 commit comments