mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
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:
parent
15308bfb7c
commit
1e674d18c9
2 changed files with 10 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue