import { useRef, useState, useEffect, useCallback } from 'react';

// useState can cause memory leaks if it is set after the component unmounted. For example, if it is
// set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
const useAsyncState = (initialState)=>{
    const isMounted = useRef(true);
    const [state, setState] = useState(initialState);
    useEffect(()=>{
        isMounted.current = true;
        return ()=>{
            isMounted.current = false;
        };
    }, []);
    const setStateAction = useCallback((newState)=>{
        if (isMounted.current) {
            setState(newState);
        }
    }, []);
    return [
        state,
        setStateAction
    ];
};

export { useAsyncState };
//# sourceMappingURL=async.mjs.map
