File size: 369 Bytes
05c5ed5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { isFunction, nextTick } from "lib/utils";
import { useCallback, useState } from "react";

export function useUpdate() {
  const [, setState] = useState(0);

  const update = useCallback((cb?: () => void) => {
    nextTick().then(() => {
      setState((prev) => prev + 1);
      if (isFunction(cb)) {
        cb();
      }
    });
  }, []);

  return update;
}