import { useEffect , useRef , useState } from 'react' ; import type { AnyExtension , RemirrorManager } from '@remirror/core' ; import { createReactManager } from '../react-helpers' ; import type { CreateReactManagerOptions , ReactExtensions } from '../react-types' ; remarks internal export function useManager < Extension extends AnyExtension = Remirror . Extensions > ( extensions , options = { } ) { const extensionsRef = useRef ( extensions ) ; const optionsRef = useRef ( options ) ; const [ manager , setManager ] = useState ( ( ) => createReactManager ( extensions , options ) ) ; extensionsRef . current = extensions ; optionsRef . current = options ; useEffect ( ( ) => { return manager . addHandler ( 'destroy' , ( ) => { setManager ( ( ) => createReactManager ( extensionsRef . current , optionsRef . current ) ) ; } ) ; } , [ manager ] ) ; return manager ; }