0.7.10-alpha.0 • Published 1 year ago

@gaopeng123/hooks.use-throttle v0.7.10-alpha.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

useThrottle

TODO: 节流hooks

在线demo

(fn: Fn, wait: number = 200, options: ThrottleOptions = {}, dep: any[] = []): Fn

export type ThrottleOptions = {
    type?: 1 | 2; // 1 时间戳记录 2 setTimeout版本
    leading?: boolean; // 第一时间是否立即调用 后续在节流
}

Usage

import React, {useState, useEffect} from 'react';
import {useThrottle} from "@gaopeng123/hooks.use-throttle";

type TestUseThrottleProps = {};
const TestUseThrottle: React.FC<TestUseThrottleProps> = (props) => {
    const [v, setV] = useState('');
    const onChange = useThrottle((v: any) => {
        setV(v.target.value);
    }, 500);
    return (
        <React.Fragment>
            <input onChange={onChange}/>
            <br></br>输入值: {v}
        </React.Fragment>
    )
};

export default TestUseThrottle;
0.7.10-alpha.0

1 year ago

0.7.8

1 year ago

0.7.6

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.6.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.4.2

3 years ago

0.3.2

3 years ago