Why I'm in love with function components
— 1 min read
As I told you in my first post, I'm learning React again from scratch. I made a little app in 2015 with React and Firebase and React components were using React.createClass() at the time. The jump didn't seem so high at the time when I started exporimenting with VueJS. Four years have passed and the little town I left seems like a Metropolis, it's not all gold that glitters, but something really catch my eye: Function components. The beautiful, clean, simple way to declare components like a function, with props and children as parameters. Let's see an example:
To me this is beatiful, simple but powerful. With the release of Hooks in React 16.8 you don't need a class anymore so function components are a wonderful way to write an application: just write functions!
Hooks let you use state and other React features without writing a class. You can also build your own Hooks to share reusable stateful logic between components.