fix(frontend): missing dependency in useCallback

To avoid endless re-render we also have to use a constant empty array
as the initialValue.
This commit is contained in:
Julian Tölle 2020-11-07 19:14:41 +01:00
parent 15308bfb7c
commit 1e674d18c9
2 changed files with 10 additions and 5 deletions

View file

@ -1,4 +1,4 @@
import React, { useState, useEffect, useCallback } from "react";
import { useCallback, useEffect, useState } from "react";
type UseAsync = <T>(
asyncFunction: () => Promise<T>,
@ -25,7 +25,7 @@ export const useAsync: UseAsync = <T extends any>(
.then((response) => setValue(response))
.catch((err) => setError(err))
.finally(() => setPending(false));
}, [asyncFunction]);
}, [asyncFunction, initialValue]);
// Call execute if we want to fire it right away.
// Otherwise execute can be called later, such as