@dever/vhooks
v1.2.0
Published
some hooks support vue
Downloads
3
Readme
vue-hooks
介绍
some hooks support vue
安装教程
yarn add @dever/vhooks
使用说明
- 初始化
import { install } from '@dever/vhooks'
install()
- 使用withHook包裹vue组件,像react一样,在函数组件中使用hook,主要api如下
import { withHooks, useRef, useEffect, useState, useCallback, useMemo, useLayoutEffect } from '@dever/vhooks'
- 示例
import { withHooks, useState, useRef, useEffect, useCallback } from '@dever/vhooks'
export default withHooks(function (h, props) {
const instance = useRef({})
const [count1, setCount1] = useState(0)
const [count2, setCount2] = useState(0)
useEffect(() => {
// mounted
instance.current.ismounted = true
return () => {
// destoryed
}
}, [])
const onClick = useCallback(() => {
setCount1((count) => ++count)
}, [])
return (
<div>
demo
<button
onClick={onClick}
>
点我{count1}
</button>
<button
onClick={() => {
setCount2((count) => ++count)
}}
>
继续点我{count2}
</button>
</div>
)
})