1.2.0 • Published 1 year ago

@dever/vhooks v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

vue-hooks

介绍

some hooks support vue

安装教程

yarn add @dever/vhooks

使用说明

  1. 初始化
    import { install } from '@dever/vhooks'
    install()
  2. 使用withHook包裹vue组件,像react一样,在函数组件中使用hook,主要api如下 import { withHooks, useRef, useEffect, useState, useCallback, useMemo, useLayoutEffect } from '@dever/vhooks'
  3. 示例
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>
        )
    })
1.2.0

1 year ago

1.1.6

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.0

1 year ago