1 | "use strict";
|
2 |
|
3 | var _typeof = require("@babel/runtime/helpers/typeof");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = exports.RenderBlock = void 0;
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
10 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
11 |
|
12 |
|
13 | function useRenderTimes(props, debug) {
|
14 |
|
15 | var timesRef = React.useRef(0);
|
16 | timesRef.current += 1;
|
17 |
|
18 |
|
19 | var propsRef = React.useRef(props);
|
20 | var keys = [];
|
21 | Object.keys(props || {}).map(function (key) {
|
22 | var _propsRef$current;
|
23 | if ((props === null || props === void 0 ? void 0 : props[key]) !== ((_propsRef$current = propsRef.current) === null || _propsRef$current === void 0 ? void 0 : _propsRef$current[key])) {
|
24 | keys.push(key);
|
25 | }
|
26 | });
|
27 | propsRef.current = props;
|
28 |
|
29 |
|
30 | var keysRef = React.useRef([]);
|
31 | if (keys.length) {
|
32 | keysRef.current = keys;
|
33 | }
|
34 | React.useDebugValue(timesRef.current);
|
35 | React.useDebugValue(keysRef.current.join(', '));
|
36 | if (debug) {
|
37 | console.log("".concat(debug, ":"), timesRef.current, keysRef.current);
|
38 | }
|
39 | return timesRef.current;
|
40 | }
|
41 | var _default = exports.default = process.env.NODE_ENV !== 'production' ? useRenderTimes : function () {};
|
42 | var RenderBlock = exports.RenderBlock = React.memo(function () {
|
43 | var times = useRenderTimes();
|
44 | return React.createElement("h1", null, "Render Times: ", times);
|
45 | });
|
46 | if (process.env.NODE_ENV !== 'production') {
|
47 | RenderBlock.displayName = 'RenderBlock';
|
48 | } |
\ | No newline at end of file |