Transform React.js Hooks to Vue.js Composition Api
const [counter, setCounter] = useState(0); // React Hooks
// Transforms into
const counter = reactive(0); // Vue Composition Api
Clone the respository and run npm i
.
To run dev server execute npm run dev
command.
- remove cleanup callback from
onMounted
- create
watch
if contains dependencies - create
onMounted
if dependencies are empty - create
onUpdated
if there are no dependencies - if contains cleanup callback
- create
onMounted
hook - remove return cleanup callback from original callback
- create additional
onUnmounted
lifecycle cleanup hook
- create
- replace
useRef
withref
- replace
.current
with.value
- replace
useState
withref
orreactive
- transform
setState
call with raw expression - if was transformed to
ref
- replace every value access with
.value
member property access
- replace every value access with
- transform initial state function provider to
ref
orreactive
IIFE - unwrap callback's body from
setState
call- rename argument to used in state declaration
- rename argument in complex function body
- replace
useCallback
with wrapped callback incomputed
- replace
useCallback
with raw callback
- replace
useMemo
withcomputed
- replace
useContext
withinject
- replace
useLayoutEffect
withonBeforeMount
- if has cleanup callback
- create additional
onUnmounted
lifecycle hook
- create additional