Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3427 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3427 Rev 3428
Línea 4... Línea 4...
4
  apiFunction,
4
  apiFunction,
5
  options = {
5
  options = {
6
    autofetch: false,
6
    autofetch: false,
7
    autofetchDependencies: [],
7
    autofetchDependencies: [],
8
    initialArgs: [],
8
    initialArgs: [],
-
 
9
    onSuccess: () => {},
-
 
10
    onError: () => {},
9
  }
11
  }
10
) {
12
) {
11
  const [data, setData] = useState(null);
13
  const [data, setData] = useState(null);
12
  const [error, setError] = useState(null);
14
  const [error, setError] = useState(null);
13
  const [loading, setLoading] = useState(false);
15
  const [loading, setLoading] = useState(false);
14
  const {
16
  const {
15
    autofetch = false,
17
    autofetch = false,
16
    autofetchDependencies = [],
18
    autofetchDependencies = [],
17
    initialArgs = [],
19
    initialArgs = [],
-
 
20
    onSuccess = () => {},
-
 
21
    onError = () => {},
18
  } = options;
22
  } = options;
Línea 19... Línea 23...
19
 
23
 
20
  const execute = useCallback(
24
  const execute = useCallback(
21
    async (...args) => {
25
    async (...args) => {
Línea 36... Línea 40...
36
    [apiFunction]
40
    [apiFunction]
37
  );
41
  );
Línea 38... Línea 42...
38
 
42
 
39
  useEffect(() => {
43
  useEffect(() => {
40
    if (autofetch) {
44
    if (autofetch) {
-
 
45
      execute(...initialArgs)
-
 
46
        .then(onSuccess)
41
      execute(...initialArgs);
47
        .catch(onError);
42
    }
48
    }
43
    // eslint-disable-next-line react-hooks/exhaustive-deps
49
    // eslint-disable-next-line react-hooks/exhaustive-deps
Línea 44... Línea 50...
44
  }, [autofetch, execute, ...autofetchDependencies, ...initialArgs]);
50
  }, [autofetch, execute, ...autofetchDependencies, ...initialArgs]);