import { useEffect } from 'react' ; import useCheckAuth from './useCheckAuth' ; import { useSafeSetState } from '../util/hooks' ; interface State { loading : boolean ; loaded : boolean ; authenticated ? : boolean ; } const emptyParams = { } ; see useAuthenticated param { Object } params returns example const useAuthState = ( params = emptyParams ) : State => { const [ state , setState ] = useSafeSetState ( { loading : true , loaded : false , authenticated : true , } ) ; const checkAuth = useCheckAuth ( ) ; useEffect ( ( ) => { checkAuth ( params , false ) . then ( ( ) => setState ( { loading : false , loaded : true , authenticated : true } ) ) . catch ( ( ) => setState ( { loading : false , loaded : true , authenticated : false } ) ) ; } , [ checkAuth , params , setState ] ) ; return state ; } ; export default useAuthState ;