UNPKG

wavesurfer-react

Version:
26 lines (23 loc) 665 B
import { useRef, useEffect } from 'react'; // TODO: try to merge it with useRegionEvent function useRegionPluginEvent(ref, eventName, callback) { const callbackRef = useRef(null); useEffect(()=>{ if (!ref) { return; } if (callback) { callbackRef.current = (...args)=>callback(...args); ref.on(eventName, callbackRef.current); } return ()=>{ callbackRef.current && ref.un(eventName, callbackRef.current); callbackRef.current = null; }; }, [ ref, eventName, callback ]); } export { useRegionPluginEvent as default };