You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
894 B
29 lines
894 B
"use strict";
|
|
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = useMemoCallback;
|
|
|
|
var React = _interopRequireWildcard(require("react"));
|
|
|
|
/**
|
|
* Cache callback function that always return same ref instead.
|
|
* This is used for context optimization.
|
|
*/
|
|
function useMemoCallback(func) {
|
|
var funRef = React.useRef(func);
|
|
funRef.current = func;
|
|
var callback = React.useCallback(function () {
|
|
var _funRef$current;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
return (_funRef$current = funRef.current) === null || _funRef$current === void 0 ? void 0 : _funRef$current.call.apply(_funRef$current, [funRef].concat(args));
|
|
}, []);
|
|
return func ? callback : undefined;
|
|
} |