Skip to content

Commit

Permalink
fix: synchronously re-render bug of useRaf hook (#77)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hijiangtao authored and streamich committed Dec 16, 2018
1 parent 30cee86 commit 5d74348
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/useRaf.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {useState, useEffect} from './react';
import {useState, useLayoutEffect} from './react';

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

useEffect(() => {
useLayoutEffect(() => {
let raf, timerStop, start;

const onFrame = () => {
Expand Down

0 comments on commit 5d74348

Please sign in to comment.