When you use React for development, how often do you have to convert a class component to a functional component?
Recently I had this issue where I had to re-use some components from an old project and in order to match the code style of the current component, I had to convert those class components to the functional components.
I tried searching for an online tool that could help fasten this conversion process, but there wasn't any.
What tools do you use when you try to convert a react class based component to a functional component?
If there's none and anyone wants to build a tool for it, I will try to help with it.
I personally haven't hated doing this by hand previously. If your class component is complicated enough that it's not an easy by-hand change, then the problem might actually be that your component is trying to do too many things.
Personally I don’t rewrite old components to hooks. Classes don’t go anywhere so I don’t see a problem in having class components with functional components inside one code base.
I’m not sure it’s possible to automate this and catch all edge cases, although I suppose an automated tool could get you 80% of the way there by adding useState and converting lifecycle methods to useEffect. I generally do this by hand and haven’t found it to be a big deal. I have some older components as class components and I won’t bother refactoring unless I really need to take advantage of hooks.