This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type UnsubscribeFunc = () => void; | |
function useEvent(subscribeFunc: () => UnsubscribeFunc, deps: any[] = []) { | |
// we use ref instead of useMemo because on strict mode useMemo is being called twice | |
const unsubscribeFunc = useRef(subscribeFunc()); | |
useEffect(() => { | |
// this will only be called after a change in deps. | |
// initial subscription happens sooner than useEffect | |
if (!unsubscribeFunc.current) { |