import { Ref , onMounted , onBeforeMount , unref } from '@vue/composition-api' ; import ResizeSensor from 'resize-sensor' ; export default function useResizeSensor ( element , onResized , immediate = false ) { let sensor ; function setup ( el ) { sensor = new ResizeSensor ( el , ( ) => onResized ( el ) ) ; if ( immediate ) { onResized ( el ) ; } } onMounted ( ( ) => { const el = unref ( element ) ; if ( ! el ) return ; setup ( el ) ; } ) ; onBeforeMount ( ( ) => { if ( sensor ) { sensor . detach ( ) ; } } ) ; }