Skip to content

Instantly share code, notes, and snippets.

View icedevml's full-sized avatar

Michał Leszczyński icedevml

View GitHub Profile
@icedevml
icedevml / useAsyncEffectState.ts
Created May 30, 2025 01:29
React Hook to safely combine useState and async calls
/**
* useAsyncEffect - safely use async/await within React effects
*
* Original code by François Zaninotto from: https://marmelab.com/blog/2023/01/11/use-async-effect-react.html
* Modified by Michał Leszczyński (icedev.pl)
*/
import {useEffect, useState, useMemo, useRef, type DependencyList} from 'react'
interface IUseAsyncEffectResultNotReady {