text: import { useState, useEffect } from 'react';
  
  // API
  import API from '../API';
  
  const initialState = {
      page: 0,
      results: [],
      total_pages: 0,
      total_results: 0
  }
  
  export const useHomeFetch = () => {
  
      const [searchTerm, setSearchTerm] = useState('');
      const [state, setState] = useState(initialState);
      const [loading, setLoading] = useState(false);
      const [error, setError] = useState(false);
  
      //console.log("Search term : " + searchTerm)
  
      const fetchBooks = async (searchTerm) => {
  
          setError(false);
          setLoading(true);
  
          try {
              const apiResponse = await API.fetchBooks(searchTerm);
              console.log("Api response ", { ...apiResponse });
              
              if (apiResponse.status == "OK") {
                  setState({ results: [...apiResponse.results.books] })                
              } else {
                  setError(true);
                  setState({ results: [...apiResponse.errors] })
              }
  
          } catch (error) {
              setError(true);
          }
  
          setLoading(false);
      }
  
      useEffect(() => {
          setState(initialState);
          fetchBooks(searchTerm)
      }, [searchTerm]);
  
      return { state, loading, error, setSearchTerm, searchTerm };
  }