Here is a example for PropTypes:
import PropTypes from \'prop-types\';
class Greeting extends React.Component {
render() {
return (
Hello,
The idea behind react is component base. Prop-types is runtime type checking for React props and similar objects. You can use prop-types to document the intended types of properties passed to components.
In Greeting
component, if you need name
as a props, you have to define it on the prop-types. If name
is required, you define it is required:
Greeting.propTypes = {
name: PropTypes.string.isRequired
};
To use Greeting
, you just call it and pass props to it. I don't think we need to check what we have pass into Greeting
component.