MCPcopy
hub / github.com/marmelab/react-admin / useEvent

Function useEvent

packages/ra-core/src/util/useEvent.ts:14–26  ·  view source on GitHub ↗
(
    fn: (...args: Args) => Return
)

Source from the content-addressed store, hash-verified

12 * @see https://github.com/facebook/react/issues/14099#issuecomment-440013892
13 */
14export const useEvent = <Args extends unknown[], Return>(
15 fn: (...args: Args) => Return
16): ((...args: Args) => Return) => {
17 const ref = React.useRef<(...args: Args) => Return>(() => {
18 throw new Error('Cannot call an event handler while rendering.');
19 });
20
21 useLayoutEffect(() => {
22 ref.current = fn;
23 });
24
25 return useCallback((...args: Args) => ref.current(...args), []);
26};

Callers 15

MenuItemLink.tsxFile · 0.90
SimpleListItemFunction · 0.90
InfinitePaginationFunction · 0.90
FilterListItem.tsxFile · 0.90
AutocompleteInputFunction · 0.90
DateInputFunction · 0.90
SimpleFormIteratorFunction · 0.90
DataTableRowFunction · 0.90
SimpleFormIteratorFunction · 0.90
useSelectAllFunction · 0.90

Calls

no outgoing calls

Tested by 1

ParentFunction · 0.72