Skip to content
Snippets Groups Projects
useFindUser.ts 616 B
Newer Older
  • Learn to ignore specific revisions
  • import { useState, useEffect } from 'react'
    import axios from 'axios'
    import { User } from '../models/user.model'
    
    const useFindUser = () => {
      const [user, setUser] = useState<User | null>(null)
      const [isLoading, setLoading] = useState<boolean>(true)
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      const _apiUrl: string = 'https://localhost:443/'
    
    
      useEffect(() => {
        async function findUser() {
          const { data } = await axios.get(`${_apiUrl}api/common/WhoAmI`)
          if (data) {
            setUser(data)
            setLoading(false)
          }
        }
        findUser()
      }, [])
      return {
        user,
        setUser,
        isLoading,
      }
    }
    
    export default useFindUser