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.

15 lines 514 B
import _isFunction from "lodash/isFunction"; import _get from "lodash/get"; import { useState, useEffect } from 'react'; import { getActiveElement } from '../index'; /* istanbul ignore next */ export function usePrevFocus() { const [prevFocusElement, setPrevFocus] = useState(getActiveElement()); useEffect(() => { return function cleanup() { const blur = _get(prevFocusElement, 'blur'); _isFunction(blur) && blur(); }; }, [prevFocusElement]); return [prevFocusElement, setPrevFocus]; }