Const instead of class

Tell us what’s happening:
Hi guys, I do not understand yet why the Camper component has been declared using const instead of class (as the Campsite component).

Can anyone explain to me why that is the case? Thanks in advance.

Your code so far

class CampSite extends React.Component {
constructor(props) {
render() {
  return (
// Change code below this line
const Camper = props => <p>{}</p>;

Camper.defaultProps = {
name: "CamperBot"

Camper.propTypes = {
name: PropTypes.string.isRequired
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 13421.102.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.199 Safari/537.36.

Challenge: Review Using Props with Stateless Functional Components

Link to the challenge:

There are two ways to declare components in React - as a class or as a functional component (e.g., using const).

It used to be that classes were used when you needed state on a component level or if you needed lifecycle methods. You used functional components with everything else because they are lighter and faster.

But now, with hooks, functional components can do everything that class components can. It’s still important to learn class components because you will still see a lot of them, but functional components and hooks seem to be the future. But you haven’t learned hooks yet, so don’t worry about that - there will be plenty of time.

1 Like

Thank you for your explanation!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.