@pdftron/webviewer-react-toolkit
Version:
A React component library for integrating with PDFTron WebViewer API.
20 lines (19 loc) • 848 B
JavaScript
import { useCallback, useState } from 'react';
/**
* Returns handlers for onFocus and onBlur, as well as a property focused which
* is true if the component or any child is being focused.
* @param onFocus The onFocus prop if it's available.
* @param onBlur The onBlur prop if it's available.
*/
export function useFocus(onFocus, onBlur) {
var _a = useState(false), focused = _a[0], setFocused = _a[1];
var handleOnFocus = useCallback(function (event) {
setFocused(true);
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
}, [onFocus]);
var handleOnBlur = useCallback(function (event) {
setFocused(false);
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
}, [onBlur]);
return { focused: focused, handleOnFocus: handleOnFocus, handleOnBlur: handleOnBlur };
}