mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
19 lines
436 B
TypeScript
19 lines
436 B
TypeScript
import shim from '../shim';
|
|
const { useEffect } = shim.react();
|
|
|
|
export interface AsyncEffectEvent {
|
|
cancelled: boolean;
|
|
}
|
|
|
|
export type EffectFunction = (event: AsyncEffectEvent)=> Promise<void>;
|
|
|
|
export default function(effect: EffectFunction, dependencies: any[]) {
|
|
useEffect(() => {
|
|
const event: AsyncEffectEvent = { cancelled: false };
|
|
void effect(event);
|
|
return () => {
|
|
event.cancelled = true;
|
|
};
|
|
}, dependencies);
|
|
}
|