mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 22:39:34 +08:00
c321492eeb
* fix: slider tooltip pos * chore: clean up * chore: fix style * chore: bump rc-slider * fix: lock clean up logic * chore: finish * test: update snapshot * chore: bump rc-slider * test: update snapshot * test: test coverage * chore: clean up
28 lines
610 B
TypeScript
28 lines
610 B
TypeScript
import * as React from 'react';
|
|
import raf from 'rc-util/lib/raf';
|
|
|
|
export default function useRafLock(): [state: boolean, setState: (nextState: boolean) => void] {
|
|
const [state, setState] = React.useState(false);
|
|
|
|
const rafRef = React.useRef<number>();
|
|
const cleanup = () => {
|
|
raf.cancel(rafRef.current!);
|
|
};
|
|
|
|
const setDelayState = (nextState: boolean) => {
|
|
cleanup();
|
|
|
|
if (nextState) {
|
|
setState(nextState);
|
|
} else {
|
|
rafRef.current = raf(() => {
|
|
setState(nextState);
|
|
});
|
|
}
|
|
};
|
|
|
|
React.useEffect(() => cleanup, []);
|
|
|
|
return [state, setDelayState];
|
|
}
|