Review Using Props with Stateless Functional Components

Tell us what’s happening:
The test case fails saying “The Camper component should include prop types which require the name prop to be of type string”.

Your code so far


class CampSite extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div>
        <Camper name="Prem"/>
      </div>
    );
  }
};
// change code below this line
const Camper = (props) => <p>{props.name}</p>

Camper.defaultProps = {name:'CamperBot'};
Camper.propTypes = { name:PropTypes.string.IsRequired };



  


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/review-using-props-with-stateless-functional-components

Re-check and fix this line to pass the test.

1 Like

Solution to pass the test:

// change code below this line
const Camper = (props) => <p>{props.name}</p>

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

1 Like

class CampSite extends React.Component {
constructor(props) {
super(props);
}
render() {
return (

); } }; class Camper extends React.Component { constructor(props) { super(props); } render() { return (

{this.props.name}

);
}
};

Camper.propTypes = {name:PropTypes.string.isRequired};
Camper.defaultProps = { name : “user”};
Camper.defaultProps = {name:‘CamperBot’};
Camper.propTypes = { name:PropTypes.string.IsRequired };

1 Like

name:PropTypes.string.isRequired