Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3599 Rev 3658
Línea 5... Línea 5...
5
 
5
 
6
const getResources = async (url, params) => {
6
const getResources = async (url, params) => {
7
  return await api.get(url, { params });
7
  return await api.get(url, { params });
Línea 8... Línea 8...
8
};
8
};
9
 
9
 
10
export function useFetch(url, { params = undefined } = {}) {
10
export function useFetch(url) {
11
  const { showError } = useAlert();
11
  const { showError } = useAlert();
Línea 12... Línea 12...
12
  const { loading, data, error, execute } = useApi(getResources);
12
  const { loading, data, error, execute } = useApi(getResources);
13
  const hasFetched = useRef(false);
13
  const hasFetched = useRef(false);
14
 
14
 
15
  useEffect(() => {
15
  useEffect(() => {
16
    if (!hasFetched.current && url) {
16
    if (!hasFetched.current && url) {
17
      execute(url, params);
17
      execute(url);
18
      hasFetched.current = true;
18
      hasFetched.current = true;
19
    } else if (url || params) {
19
    } else if (url) {
Línea 20... Línea 20...
20
      execute(url, params);
20
      execute(url);
21
    }
21
    }
22
  }, [url, params, execute]);
22
  }, [url, execute]);
Línea 23... Línea 23...
23
 
23
 
24
  useEffect(() => {
24
  useEffect(() => {
25
    if (error) showError(error);
25
    if (error) showError(error);
26
  }, [error, showError]);
26
  }, [error, showError]);
27
 
27
 
28
  return {
28
  return {