1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 23:04:21 +00:00
sophon/frontend/src/hooks/useAbortEffect.ts

19 lines
379 B
TypeScript

import * as React from "react";
export type AbortableEffect = (abort: AbortSignal) => void
export function useAbortEffect(effect: AbortableEffect) {
React.useEffect(
() => {
const abort = new AbortController()
effect(abort.signal)
return () => {
abort.abort()
}
},
[effect]
)
}