This extension provides a command to trigger a React codemod that turns class components into functional components.
Warning: the current state is a minimalistic program that only supports TSX.
In VS Code, open a module containing class components, then open the Command Palette and execute react-class-to-functional.transform.
This will turn all classes into functions without saving the changes.
It looks for classes extending React.Component (literally) then applies the following modifications:
- the
rendermethod becomes the component itself; componentDidMount,componentDidUpdateandcomponentWillUnmountare turned intouseEffectcalls;React.createRefcalls are turned intouseRefcalls;- state is split into multiple
useStatecalls; - props are retrieved and declared in the function arguments;
- methods are turned into internal functions;
thiskeywords are removed;- state interface is removed;
- React import is adapted.