[ABANDONED] React/Redux front end for the Flexor social network.
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.
 
 

31 lines
969 B

import { useEffect, useRef, EffectCallback } from 'react'
import { useSelector } from 'react-redux'
import { useHistory } from 'react-router-dom'
import isEqual from 'lodash/isEqual'
import { getAuthenticated, getChecked } from 'src/selectors/authentication'
import { AppState } from 'src/types'
export const useAuthenticationCheck = () => {
const checked = useSelector<AppState, boolean>(getChecked)
const authenticated = useSelector<AppState, boolean>(getAuthenticated)
const history = useHistory()
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))
}