mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-23 07:14:21 +00:00
20 lines
379 B
TypeScript
20 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]
|
||
|
)
|
||
|
}
|