UNPKG

devexpress-reporting-react

Version:

DevExpress Reporting React provides the capability to develop a reporting application to create and customize reports.

23 lines (22 loc) 902 B
import React from 'react'; import { KeyboardEnum } from '@devexpress/analytics-core/property-grid/widgets/internal/_utils'; const useDxAction = (ref, action, model) => { React.useEffect(() => { const element = ref.current; if (!element) return undefined; const handleClick = (e) => action.call(model, model, e); const handleKeyDown = (e) => { if (e.key == KeyboardEnum.Enter || e.key == KeyboardEnum.Space) { action.call(model, model, e); } }; element.addEventListener('click', handleClick); element.addEventListener('keydown', handleKeyDown); return () => { element.removeEventListener('click', handleClick); element.removeEventListener('keydown', handleKeyDown); }; }, [ref.current, action, model, ref.current]); }; export default useDxAction;