UNPKG

@douyinfe/semi-ui

Version:

A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.

17 lines (14 loc) 522 B
import { useState, useEffect } from 'react'; import { getActiveElement } from '../index'; import { get, isFunction } from 'lodash'; /* istanbul ignore next */ export function usePrevFocus() { const [prevFocusElement, setPrevFocus] = useState<HTMLElement>(getActiveElement()); useEffect(() => { return function cleanup() { const blur = get(prevFocusElement, 'blur'); isFunction(blur) && blur(); }; }, [prevFocusElement]); return [prevFocusElement, setPrevFocus]; }