import { useState, useEffect } from 'react';

export const useFetch = (url: string, options?: any) => {
  const [response, setResponse] = useState(null);
  const [error, setError] = useState(null);
  const [isLoading, setIsLoading] = useState(false);

  useEffect(() => {
    const fetchData = async () => {
      setIsLoading(true);
      try {
        const result = await fetch(url, options);
        const json = await result.json();
        setResponse(json);
        setIsLoading(false);
      } catch (err) {
        setError(err);
        setIsLoading(false);
      }
    };
    fetchData();
  }, [url, options]);

  return { response, error, isLoading };
};
