Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3575 Rev 3658
Línea 1... Línea 1...
1
import { useState, useCallback } from 'react';
1
import { useState, useCallback, useEffect } from 'react';
Línea 2... Línea 2...
2
 
2
 
3
const defaultOptions = {
3
const defaultOptions = {
4
  onSuccess: () => {},
4
  onSuccess: () => {},
-
 
5
  onError: () => {},
-
 
6
  autoFetch: false,
5
  onError: () => {}
7
  autoFetchArgs: []
Línea 6... Línea 8...
6
};
8
};
7
 
9
 
-
 
10
export function useApi(apiFunction, options = defaultOptions) {
-
 
11
  const { onSuccess, onError, autoFetch, autoFetchArgs } = {
-
 
12
    ...defaultOptions,
Línea 8... Línea 13...
8
export function useApi(apiFunction, options = defaultOptions) {
13
    ...options
9
  const { onSuccess, onError } = { ...defaultOptions, ...options };
14
  };
10
 
15
 
Línea 31... Línea 36...
31
      }
36
      }
32
    },
37
    },
33
    [apiFunction, onSuccess, onError]
38
    [apiFunction, onSuccess, onError]
34
  );
39
  );
Línea -... Línea 40...
-
 
40
 
-
 
41
  useEffect(() => {
-
 
42
    if (autoFetch) {
-
 
43
      execute(...autoFetchArgs);
-
 
44
    }
-
 
45
  }, [execute, autoFetch, JSON.stringify(autoFetchArgs)]);
35
 
46
 
36
  return { loading, data, error, execute };
47
  return { loading, data, error, execute };