import { useEffect, useState } from 'react'

function useLogin<T>(url: string) {
  const [response, setResponse] = useState<T>()
  const [error, setError] = useState(null)
  const [isLoading, setIsLoading] = useState(true)
  useEffect(() => {
    const fetchData = async () => {
      setIsLoading(true)
      try {
        const res = await fetch(url)
        const json = await res.json()
        setResponse(json)
        setIsLoading(false)
      } catch (error) {
        setError(error)
      }
    }
    fetchData()
  }, [])
  return { response, error, isLoading }
}

export default useLogin
