Files
2018-10-16 21:32:40 +05:30

689 B

title
title
Review Using Props with Stateless Functional Components

Review Using Props with Stateless Functional Components

Hints

  • A functional(a.k.a. stateless) component is just a plain javascript function which takes props as an argument and returns a react element.
  • Use Component.defaultProps to set default props.
  • Use Component.propTypes to set props types.

Solution

const Camper = props => (<p>{props.name}</p>);

Camper.defaultProps = {
  name: 'CamperBot'
};

Camper.propTypes = {
  name: PropTypes.string.isRequired
};