Tell us what’s happening:
Describe your issue in detail here.
I am writing a class component instead of the functional one, and as per my understanding I am adding default prop & making the name key as string and required.
However following code is not working. can anyone explain where am I going wrong with this ?
class CampSite extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<Camper />
</div>
);
}
};
class Camper extends React.Component {
static propTypes = {
name: PropTypes.string.isRequired
};
static defaultProps = {
name: 'CamperBot'
};
render() {
return (
<p>Hello, {this.props.name}!</p>
);
}
}
jsx
class CampSite extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<Camper/>
</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/112.0.0.0 Safari/537.36 Edg/112.0.1722.68
Challenge: React - Review Using Props with Stateless Functional Components
Link to the challenge: