nextemos 2.3.6 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,3 @@
1
1
  export { default as useFetch } from './useFetch';
2
2
  export { default as useLocalStorage } from './useLocalStorage';
3
+ export { default as useWindowSize } from './useWindowSize';
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useLocalStorage = exports.useFetch = void 0;
6
+ exports.useWindowSize = exports.useLocalStorage = exports.useFetch = void 0;
7
7
  /// hooks
8
8
  var useFetch_1 = require("./useFetch");
9
9
  Object.defineProperty(exports, "useFetch", { enumerable: true, get: function () { return __importDefault(useFetch_1).default; } });
10
10
  var useLocalStorage_1 = require("./useLocalStorage");
11
11
  Object.defineProperty(exports, "useLocalStorage", { enumerable: true, get: function () { return __importDefault(useLocalStorage_1).default; } });
12
+ var useWindowSize_1 = require("./useWindowSize");
13
+ Object.defineProperty(exports, "useWindowSize", { enumerable: true, get: function () { return __importDefault(useWindowSize_1).default; } });
@@ -0,0 +1,14 @@
1
+ interface IWindowSize {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ /**
6
+ * useWindowSize Hook
7
+ *
8
+ * @description
9
+ * A custom React hook that listens for the window size and returns it.
10
+ *
11
+ * @returns {Object} An object containing the width and height of the window window.
12
+ */
13
+ declare const useWindowSize: () => IWindowSize;
14
+ export default useWindowSize;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ /**
5
+ * useWindowSize Hook
6
+ *
7
+ * @description
8
+ * A custom React hook that listens for the window size and returns it.
9
+ *
10
+ * @returns {Object} An object containing the width and height of the window window.
11
+ */
12
+ const useWindowSize = () => {
13
+ const [windowSize, setWindowSize] = (0, react_1.useState)({
14
+ width: window.innerWidth,
15
+ height: window.innerHeight,
16
+ });
17
+ /**
18
+ * handleResize
19
+ *
20
+ * @description
21
+ * A function to update the window size state when the window is resized.
22
+ */
23
+ const handleResize = () => {
24
+ setWindowSize({
25
+ width: window.innerWidth,
26
+ height: window.innerHeight,
27
+ });
28
+ };
29
+ /**
30
+ * useEffect Hook
31
+ *
32
+ * @description
33
+ * A React hook that is used for side-effects in functional components.
34
+ *
35
+ * @params {Function} () => {} A callback function that contains the side-effect logic.
36
+ * @params {Array} [] An array of dependencies. When empty, it means the useEffect runs once after the initial render.
37
+ */
38
+ (0, react_1.useEffect)(() => {
39
+ window.addEventListener('resize', handleResize);
40
+ return () => {
41
+ window.removeEventListener('resize', handleResize);
42
+ };
43
+ }, []);
44
+ return windowSize;
45
+ };
46
+ exports.default = useWindowSize;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextemos",
3
- "version": "2.3.6",
3
+ "version": "2.3.7",
4
4
  "description": "For helpers and hooks used in NextJS projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",