Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3487 | Rev 3496 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import { api } from '@api';
import { useApi } from './useApi';
import { useAlert } from './useAlert';

const getResources = async (url, config) => {
  return await api.get(url, config);
};

export function useFetch(url, config = { params: undefined }) {
  const { showError } = useAlert();

  const { loading, data, execute } = useApi(getResources, {
    autofetch: true,
    autofetchDependencies: [url, config],
    initialArgs: [url, config],
    onSuccess: (userData) => {
      console.log('User data fetched successfully:', userData);
    },
    onError: (err) => {
      console.error('Failed to fetch user data:', err);
      showError(err.message);
    }
  });

  return {
    data,
    loading,
    refetch: execute
  };
}