ReactBeginner#fundamentals

What is the key difference between class and function components?

Function components with hooks are the standard: less boilerplate, easier logic reuse and better minification. Class components use this, lifecycle methods and are still needed only for error boundaries.

Example
// function
function C(){ const [n,setN] = useState(0); return <b>{n}</b>; }
// class
class C extends React.Component { state = { n: 0 }; render(){ return <b>{this.state.n}</b>; } }

Related Questions

1
ReactIntermediate#debugging

How do you debug a React app?

Open
2
ReactAdvanced#testing

How do you test React components?

Open
3
ReactIntermediate#accessibility

What accessibility basics should a React component follow?

Open