Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3494 | Rev 3497 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3494 Rev 3496
Línea 1... Línea 1...
1
import { api } from '@api';
1
import { api } from '@api';
2
import { useApi } from './useApi';
2
import { useApi } from './useApi';
3
import { useAlert } from './useAlert';
3
import { useAlert } from './useAlert';
-
 
4
import { useEffect } from 'react';
Línea 4... Línea 5...
4
 
5
 
5
const getResources = async (url, config) => {
6
const getResources = async (url, config) => {
6
  return await api.get(url, config);
7
  return await api.get(url, config);
Línea 7... Línea 8...
7
};
8
};
8
 
9
 
Línea 9... Línea 10...
9
export function useFetch(url, config = { params: undefined }) {
10
export function useFetch(url, config = { params: undefined }) {
-
 
11
  const { showError } = useAlert();
10
  const { showError } = useAlert();
12
 
11
 
13
  const { loading, data, error, execute } = useApi(getResources);
12
  const { loading, data, execute } = useApi(getResources, {
14
 
13
    autofetch: true,
-
 
14
    autofetchDependencies: [url, config],
-
 
15
    initialArgs: [url, config],
15
  useEffect(() => {
16
    onSuccess: (userData) => {
16
    execute(url, config);
17
      console.log('User data fetched successfully:', userData);
-
 
18
    },
17
  }, [url, config]);
19
    onError: (err) => {
-
 
20
      console.error('Failed to fetch user data:', err);
18
 
Línea 21... Línea 19...
21
      showError(err.message);
19
  useEffect(() => {
22
    }
20
    if (error) showError(error);
23
  });
21
  }, [error]);
24
 
22
 
25
  return {
23
  return {
26
    data,
24
    data,