You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
687 B
23 lines
687 B
import { useEffect, useRef, EffectCallback } from 'react'
|
|
import { History } from 'history'
|
|
import isEqual from 'lodash/isEqual'
|
|
|
|
export const useAuthenticationCheck = (checked: boolean, authenticated: boolean, history: History) => {
|
|
useEffect(() => {
|
|
if (checked && !authenticated) history.push('/login')
|
|
}, [checked, authenticated])
|
|
}
|
|
|
|
const useDeepCompareMemoize = (value: any) => {
|
|
const ref = useRef()
|
|
|
|
if (!isEqual(value, ref.current)) {
|
|
ref.current = value
|
|
}
|
|
|
|
return ref.current
|
|
}
|
|
|
|
export const useDeepCompareEffect = (callback: EffectCallback, deps?: readonly any[] | undefined) => {
|
|
useEffect(callback, useDeepCompareMemoize(deps))
|
|
}
|