Install jscodeshift
through npm
npm install -g jscodeshift
Paste the Class Components in the sampleSource.jsx.
Run
npm run exec
Its just kind of co-pilot not an actual transpiler.
this.state = {
some: "useless",
};
into
const [some, setSome] = useState("useful");
this.setState({ some: "state", another: "state" });
into
setSome("state");
setAnother("state");
class Process extends Component {
constructor() {
this.formRef = React.createRef()
}
...
}
into
const Process = () => {
const formRef = useRef()
...
}
class Process extends Component {
blowUp(someArg, anotherArg) {
...
}
}
into
const Process = () => {
const blowUp = (someArg, anotherArg) => {
...
}
}
class Process extends Component {
constructor() {
doSomething()
...
}
componentDidmount() {
doSomethingElse()
...
}
componentWillunmount() {
unsubscribe()
}
}
into
const Process = () => {
useEffect(() => {
doSomething();
doSomethingElse();
return () => {
unsubscribe();
};
});
};