1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/lib/hooks/useAsyncEffect.ts

21 lines
637 B
TypeScript
Raw Normal View History

import shim from '../shim';
const { useEffect } = shim.react();
export interface AsyncEffectEvent {
cancelled: boolean;
}
export type EffectFunction = (event: AsyncEffectEvent)=> Promise<void>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
export default function(effect: EffectFunction, dependencies: any[]) {
useEffect(() => {
const event: AsyncEffectEvent = { cancelled: false };
void effect(event);
return () => {
event.cancelled = true;
};
// eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied
}, dependencies);
}