2022 Update
You only need a class
component when you:
- need to create an error boundary using
componentDidCatch
Original 2016 Answer
You only need a class
component when you:
- need the component state or
- need the lifecycle methods. such as
componentDidMount
etc.
More Related Contents:
- React component initialize state from props
- React: Passing props to function components
- React – Dynamically Import Components
- Handle response – SyntaxError: Unexpected end of input when using mode: ‘no-cors’
- What are these three dots in React doing?
- How can I communicate between related react components?
- When to use functional setState
- Reactjs async rendering of components
- Applying className/onClick/onChange not working on Custom React Component
- React – Preventing Form Submission
- CSS pseudo elements in React
- React 18, useEffect is getting called two times on mount
- How to access custom attributes from event object in React?
- this.setState isn’t merging states as I would expect
- Is there any other way to implement a “listening” function without an infinite while loop?
- Can’t type in React input text field
- How to sync Redux state and url hash tag params
- Webpack output is empty object
- Changing the layout of a component depending on Redux state
- Why is my function being called twice in React?
- How to Set port in next.js
- How to namespace es6 classes (for React components)
- Use Object.assign or Spread Operator in React/Redux? Which is a better practise
- Add a line of code to ALL functions
- Update single value in item array | react redux
- How to include local javascript on a Gatsby page?
- minimise the code since I am using the same code only the content in p tags changes and component AccordionHeader header changes
- You’re importing a component that needs useState. It only works in a Client Component, but none of its parents are marked with “use client”
- ES6 – declare a prototype method on a class with an import statement
- React props: Should I pass the object or its properties? Does it make much difference?