/
vshmidt
/
label-studio
Обзор
Документация
Войти
/
vshmidt
/
label-studio
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
web/apps/labelstudio/src/utils/hooks.ts
45 строк
914 B
yyassi-heartex
chore: OPTIC-1154: biome linting tweaks (#6425)
22 окт 2024, 23:22
Не верифицирован
22 окт 2024, 23:22
7ed55c6
Код
Авторство
О чём код?
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); };