13 lines
529 B
JavaScript
13 lines
529 B
JavaScript
import * as React from 'react';
|
|
export default function useEvent(callback) {
|
|
var fnRef = React.useRef();
|
|
fnRef.current = callback;
|
|
var memoFn = React.useCallback(function () {
|
|
var _fnRef$current;
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
return (_fnRef$current = fnRef.current) === null || _fnRef$current === void 0 ? void 0 : _fnRef$current.call.apply(_fnRef$current, [fnRef].concat(args));
|
|
}, []);
|
|
return memoFn;
|
|
} |