Function vs Class Components

Function Component (modern)

function Greeting({ name }) {
  return <h2>Hello {name}</h2>;
}

Class Component (older code)

import { Component } from 'react';

class Greeting extends Component {
  render() {
    return <h2>Hello {this.props.name}</h2>;
  }
}
Function componentClass component
Syntaxplain functionclass extending Component
StateuseState hookthis.state / this.setState
Side effectsuseEffectlifecycle methods
this keywordnot neededneeded everywhere
Use todayyes, the standardonly in legacy code / error boundaries