UNPKG

mutoid

Version:

Reactive library for data fetching, caching, state management

21 lines (20 loc) 610 B
import { useCallback, useEffect, useRef } from 'react'; export const useSubscriptionRef = () => { const subRef = useRef(null); useEffect(() => { return () => { if (subRef.current && subRef.current.closed !== true) { // eslint-disable-next-line react-hooks/exhaustive-deps subRef.current.unsubscribe(); } }; }, []); return [ subRef, useCallback(() => { if (subRef.current && subRef.current.closed !== true) { subRef.current.unsubscribe(); } }, []), ]; };