Bin
2025-12-17 611bfe34c3c96199eaaf6cf9e41a75892e44e879
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { useCallback, useEffect, useRef } from "react";
import { useHistory } from "react-router";
import { useFixedLocation } from "../providers/RoutesProvider";
 
export const useRefresh = () => {
  const history = useHistory();
  const { pathname } = useFixedLocation();
 
  const refresh = useCallback(
    (redirectPath) => {
      history.replace("/");
 
      setTimeout(() => {
        history.replace(redirectPath ?? pathname);
      }, 10);
 
      return pathname;
    },
    [pathname],
  );
 
  return refresh;
};
 
export function useFirstMountState(): boolean {
  const isFirst = useRef(true);
 
  if (isFirst.current) {
    isFirst.current = false;
 
    return true;
  }
 
  return isFirst.current;
}
 
export const useUpdateEffect: typeof useEffect = (effect, deps) => {
  const isFirstMount = useFirstMountState();
 
  useEffect(() => {
    if (!isFirstMount) {
      return effect();
    }
  }, deps);
};