2021-09-06 17:57:07 +02:00
|
|
|
import shim from '../shim';
|
|
|
|
const { useEffect } = shim.react();
|
|
|
|
|
|
|
|
export interface AsyncEffectEvent {
|
|
|
|
cancelled: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type EffectFunction = (event: AsyncEffectEvent)=> Promise<void>;
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2021-09-06 17:57:07 +02:00
|
|
|
export default function(effect: EffectFunction, dependencies: any[]) {
|
|
|
|
useEffect(() => {
|
|
|
|
const event: AsyncEffectEvent = { cancelled: false };
|
|
|
|
void effect(event);
|
|
|
|
return () => {
|
|
|
|
event.cancelled = true;
|
|
|
|
};
|
2022-08-19 13:10:04 +02:00
|
|
|
// eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied
|
2021-09-06 17:57:07 +02:00
|
|
|
}, dependencies);
|
|
|
|
}
|