1

I've recently been using react.js to develop web interfaces for my projects. I never understood what is the difference between creating a component with a function and creating a component with a class. what is the difference?

function:

const Component = () =>{
    return(
        <div>

        </div>
    )
}
export default component

or class:

class Component extends React.Component {
    render() {
        <div>

        </div>
    }
  }
export default Component
Cimo
  • 165
  • 3
  • 7
  • 3
    [check this](https://stackoverflow.com/questions/57642594/react-difference-between-a-stateful-class-component-and-a-function-component-us), maybe next time search a little first – Tomáš Šturm Feb 25 '22 at 07:57

1 Answers1

2

The most obvious difference is the syntax. A functional component is just a plain JavaScript function that accepts props as an argument and returns a React element.

A class component requires you to extend from React. Component and create a render function that returns a React element.

functional components will give you the flexibility to use react hooks

see more differences here

saiarlen
  • 67
  • 1
  • 6