While coding this week, I had to convert one of my class components in React to a functional component.

Why would I need to do that? After all, the parent component sees the two types of components as identical. Sure, functional components can be shorter, require less boilerplate, and maybe even perform better. But that’s not why I needed to do it. I was using an npm package that had React hooks and hooks are for functional components only. React Hooks, added in React 16.8, allow functional components to manage state and replace lifecycle methods. To use the hook I needed I had to convert my class components to a functional.

Here are the steps I followed to change my class component to a functional component:

#react-hook-useeffect #useeffect #react-hook #react-hook-usestate #react

Class-less Components in React
2.20 GEEK