mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-23 20:13:04 +00:00
9729befe59
Convert token access page to React GitOrigin-RevId: d7434f0de395c47a95d00767727fbe9d43f9abca
33 lines
695 B
TypeScript
33 lines
695 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 replace = useCallback(
|
|
url => {
|
|
if (isMounted.current) {
|
|
location.replace(url)
|
|
}
|
|
},
|
|
[isMounted]
|
|
)
|
|
|
|
const reload = useCallback(() => {
|
|
if (isMounted.current) {
|
|
location.reload()
|
|
}
|
|
}, [isMounted])
|
|
|
|
return useMemo(() => ({ assign, replace, reload }), [assign, replace, reload])
|
|
}
|