overleaf/services/web/frontend/js/shared/hooks/use-location.ts
ilkin-overleaf 205cfbe816 Merge pull request #17597 from overleaf/ii-enable-checkout-component-test
[web] Enable Cypress test for creating new subscription

GitOrigin-RevId: c17efbeb6a29d8e757729cddffef46faf054da70
2024-03-28 09:04:15 +00:00

24 lines
536 B
TypeScript

import { useCallback, useMemo } from 'react'
import useIsMounted from './use-is-mounted'
import { location } from '@/shared/components/location'
export const useLocation = () => {
const isMounted = useIsMounted()
const assign = useCallback(
url => {
if (isMounted.current) {
location.assign(url)
}
},
[isMounted]
)
const reload = useCallback(() => {
if (isMounted.current) {
location.reload()
}
}, [isMounted])
return useMemo(() => ({ assign, reload }), [assign, reload])
}