import { useEffect , useState } from 'react' ; type MutationHandler < Value > = ( mutations : Array < MutationRecord > , observer : MutationObserver ) => Value ; param target param options param callback param enabled export default function useMutationObserver < Value > ( target , options , callback , enabled = true ) { const [ value , setValue ] = useState < Value > ( ) ; useEffect ( ( ) => { if ( ! enabled ) { return ; } const observer = new MutationObserver ( ( ... args ) => { setValue ( callback ( ... args ) ) ; } ) ; if ( target ) { observer . observe ( target , options ) ; } return ( ) => observer . disconnect ( ) ; } , [ target , options , callback , enabled ] ) ; return value ; }