react-async-iterators
Version:
The magic of JavaScript async iterators in React ⛓️ 🧬 🔃
24 lines • 781 B
JavaScript
import { useRef, useEffect } from 'react';
export { useEffectStrictModeSafe };
function useEffectStrictModeSafe(effect, deps) {
const isPendingTeardownRef = useRef(false);
useEffect(() => {
const teardown = effect();
if (teardown) {
isPendingTeardownRef.current = false;
return () => {
if (isPendingTeardownRef.current) {
return;
}
isPendingTeardownRef.current = true;
(async () => {
await undefined;
if (isPendingTeardownRef.current) {
teardown();
}
})();
};
}
}, deps);
}
//# sourceMappingURL=useEffectStrictModeSafe.js.map