Skip to content

Commit 5d74348

Browse files
hijiangtaostreamich
authored andcommitted
fix: synchronously re-render bug of useRaf hook (#77)
* Another animation frame will be requested before the cleanup function for `useEffect` is executed. * Use `useLayoutEffect` to replace `useEffect`, in order to guarantee `cancelAnimationFrame` can work well. More details can be found in issue #76
1 parent 30cee86 commit 5d74348

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/useRaf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {useState, useEffect} from './react';
1+
import {useState, useLayoutEffect} from './react';
22

33
const useRaf = (ms: number = 1e12, delay: number = 0): number => {
44
const [elapsed, set] = useState<number>(0);
55

6-
useEffect(() => {
6+
useLayoutEffect(() => {
77
let raf, timerStop, start;
88

99
const onFrame = () => {

0 commit comments

Comments
 (0)