Files
twenty/packages/twenty-front/src/hooks/useIsMatchingLocation.ts
Antoine Moreaux e081d8ab5e refactor(auth): simplify continueWithEmail and remove useCallback (#10068)
Refactored continueWithEmail to remove unnecessary dependencies and
simplified the useIsMatchingLocation hook by eliminating useCallback.
This reduces complexity and addresses potential infinite loop issues.
2025-02-07 09:50:23 +00:00

31 lines
806 B
TypeScript

import { matchPath, useLocation } from 'react-router-dom';
import { AppBasePath } from '@/types/AppBasePath';
import { isNonEmptyString } from '@sniptt/guards';
import { isDefined } from 'twenty-shared';
export const useIsMatchingLocation = () => {
const location = useLocation();
const addTrailingSlash = (path: string) =>
path.endsWith('/') ? path : path + '/';
const getConstructedPath = (path: string, basePath?: AppBasePath) => {
if (!isNonEmptyString(basePath)) return path;
return addTrailingSlash(basePath) + path;
};
const isMatchingLocation = (path: string, basePath?: AppBasePath) => {
const match = matchPath(
getConstructedPath(path, basePath),
location.pathname,
);
return isDefined(match);
};
return {
isMatchingLocation,
};
};