Transform React.js Hooks to Vue.js Composition Api
const [counter, setCounter] = useState(0); // React Hooks
// Transforms into
const counter = reactive(0); // Vue Composition ApiClone the respository and run npm i.
To run dev server execute npm run dev command.
- remove cleanup callback from
onMounted - create
watchif contains dependencies - create
onMountedif dependencies are empty - create
onUpdatedif there are no dependencies - if contains cleanup callback
- create
onMountedhook - remove return cleanup callback from original callback
- create additional
onUnmountedlifecycle cleanup hook
- create
- replace
useRefwithref - replace
.currentwith.value
- replace
useStatewithreforreactive - transform
setStatecall with raw expression - if was transformed to
ref- replace every value access with
.valuemember property access
- replace every value access with
- transform initial state function provider to
reforreactiveIIFE - unwrap callback's body from
setStatecall- rename argument to used in state declaration
- rename argument in complex function body
- replace
useCallbackwith wrapped callback incomputed - replace
useCallbackwith raw callback
- replace
useMemowithcomputed
- replace
useContextwithinject
- replace
useLayoutEffectwithonBeforeMount - if has cleanup callback
- create additional
onUnmountedlifecycle hook
- create additional