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

20 lines
379 B
TypeScript
Raw Normal View History

2021-09-21 14:22:50 +00:00
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]
)
}