import { useState } from 'react' ; import { PluginsExtension } from '@remirror/core' ; import { useExtension } from './use-extension' ; const noReason = { doc : false , selection : false , storedMark : false } ; /**
 * Provide the reason for the latest state update with boolean flags.
 */ export function useUpdateReason ( ) { const [ updateReason , setUpdateReason ] = useState < UpdateReason > ( noReason ) ; useExtension ( PluginsExtension , ( p ) => p . addHandler ( 'applyState' , ( { tr } ) => { const reason = { ... noReason } ; if ( tr . docChanged ) { reason . doc = true ; } if ( tr . selectionSet ) { reason . selection = true ; } if ( tr . storedMarksSet ) { reason . storedMark = true ; } setUpdateReason ( reason ) ; } ) , [ ] ) ; return updateReason ; } export interface UpdateReason { /**
     * The selection changed.
     */ selection : boolean ; /**
     * The document changed.
     */ doc : boolean ; /**
     * A stored mark was added to the current selection
     */ storedMark : boolean ; }