1

Apart from Class has state and function have not, I think we can achieve our state and function requirement with class component then why do we need Function Component in React.js?

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83

1 Answers1

-1

Practically, other than state availability, there are no boundaries between both of them, since lots of developers often mistaken one after another, and each sometimes has different understandings and definition like smart-dumb component, container-component, etc. In practical use (and some of my experience), it is often easier to use functional component because :

  1. Less noise in code, no need for extra declaration, thus improving code readability.

  2. More compact and usable in terms of code size and complexity, since it didn't hold much props and state like class component did.

  3. According to some article (https://hackernoon.com/react-stateless-functional-components-nine-wins-you-might-have-overlooked-997b0d933dbc), stateless functional component also improves performance since it didn't involve life cycle methods.

Also sometimes you don't want to write another file/class for just compact small non-reusable component that only valid through your class component.

Hilal Arsa
  • 171
  • 1
  • 3
  • 15