@grantpearceuk/hooks 0.1.0
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.
- package/README.md +403 -0
- package/lib/cjs/global.d.d.ts +7 -0
- package/lib/cjs/global.d.js +2 -0
- package/lib/cjs/index.d.ts +32 -0
- package/lib/cjs/index.js +69 -0
- package/lib/cjs/useArray/index.d.ts +2 -0
- package/lib/cjs/useArray/index.js +43 -0
- package/lib/cjs/useAsync/index.d.ts +2 -0
- package/lib/cjs/useAsync/index.js +29 -0
- package/lib/cjs/useClickOutside/index.d.ts +5 -0
- package/lib/cjs/useClickOutside/index.js +14 -0
- package/lib/cjs/useCookie/index.d.ts +2 -0
- package/lib/cjs/useCookie/index.js +26 -0
- package/lib/cjs/useCopyToClipboard/index.d.ts +2 -0
- package/lib/cjs/useCopyToClipboard/index.js +20 -0
- package/lib/cjs/useDarkMode/index.d.ts +4 -0
- package/lib/cjs/useDarkMode/index.js +18 -0
- package/lib/cjs/useDebounce/index.d.ts +2 -0
- package/lib/cjs/useDebounce/index.js +22 -0
- package/lib/cjs/useDebugInformation/index.d.ts +8 -0
- package/lib/cjs/useDebugInformation/index.js +44 -0
- package/lib/cjs/useDeepCompareEffect/index.d.ts +2 -0
- package/lib/cjs/useDeepCompareEffect/index.js +16 -0
- package/lib/cjs/useEffectOnce/index.d.ts +1 -0
- package/lib/cjs/useEffectOnce/index.js +7 -0
- package/lib/cjs/useEventListener/index.d.ts +2 -0
- package/lib/cjs/useEventListener/index.js +18 -0
- package/lib/cjs/useFetch/index.d.ts +2 -0
- package/lib/cjs/useFetch/index.js +82 -0
- package/lib/cjs/useGenerateHtmlId/index.d.ts +3 -0
- package/lib/cjs/useGenerateHtmlId/index.js +9 -0
- package/lib/cjs/useGeolocation/index.d.ts +2 -0
- package/lib/cjs/useGeolocation/index.js +26 -0
- package/lib/cjs/useHover/index.d.ts +2 -0
- package/lib/cjs/useHover/index.js +17 -0
- package/lib/cjs/useLongPress/index.d.ts +4 -0
- package/lib/cjs/useLongPress/index.js +19 -0
- package/lib/cjs/useMediaQuery/index.d.ts +1 -0
- package/lib/cjs/useMediaQuery/index.js +22 -0
- package/lib/cjs/useOnScreen/index.d.ts +2 -0
- package/lib/cjs/useOnScreen/index.js +23 -0
- package/lib/cjs/useOnlineStatus/index.d.ts +1 -0
- package/lib/cjs/useOnlineStatus/index.js +14 -0
- package/lib/cjs/usePagination/index.d.ts +9 -0
- package/lib/cjs/usePagination/index.js +22 -0
- package/lib/cjs/usePrevious/index.d.ts +2 -0
- package/lib/cjs/usePrevious/index.js +13 -0
- package/lib/cjs/useRenderCount/index.d.ts +1 -0
- package/lib/cjs/useRenderCount/index.js +11 -0
- package/lib/cjs/useScript/index.d.ts +2 -0
- package/lib/cjs/useScript/index.js +19 -0
- package/lib/cjs/useSize/index.d.ts +3 -0
- package/lib/cjs/useSize/index.js +18 -0
- package/lib/cjs/useStateWithHistory/index.d.ts +4 -0
- package/lib/cjs/useStateWithHistory/index.js +53 -0
- package/lib/cjs/useStateWithValidation/index.d.ts +2 -0
- package/lib/cjs/useStateWithValidation/index.js +14 -0
- package/lib/cjs/useStorage/index.d.ts +5 -0
- package/lib/cjs/useStorage/index.js +33 -0
- package/lib/cjs/useTimeout/index.d.ts +2 -0
- package/lib/cjs/useTimeout/index.js +26 -0
- package/lib/cjs/useToggle/index.d.ts +2 -0
- package/lib/cjs/useToggle/index.js +12 -0
- package/lib/cjs/useUpdateEffect/index.d.ts +2 -0
- package/lib/cjs/useUpdateEffect/index.js +14 -0
- package/lib/cjs/useWindowSize/index.d.ts +2 -0
- package/lib/cjs/useWindowSize/index.js +18 -0
- package/lib/esm/global.d.d.ts +7 -0
- package/lib/esm/global.d.js +1 -0
- package/lib/esm/index.d.ts +32 -0
- package/lib/esm/index.js +32 -0
- package/lib/esm/useArray/index.d.ts +2 -0
- package/lib/esm/useArray/index.js +40 -0
- package/lib/esm/useAsync/index.d.ts +2 -0
- package/lib/esm/useAsync/index.js +26 -0
- package/lib/esm/useClickOutside/index.d.ts +5 -0
- package/lib/esm/useClickOutside/index.js +8 -0
- package/lib/esm/useCookie/index.d.ts +2 -0
- package/lib/esm/useCookie/index.js +20 -0
- package/lib/esm/useCopyToClipboard/index.d.ts +2 -0
- package/lib/esm/useCopyToClipboard/index.js +14 -0
- package/lib/esm/useDarkMode/index.d.ts +4 -0
- package/lib/esm/useDarkMode/index.js +12 -0
- package/lib/esm/useDebounce/index.d.ts +2 -0
- package/lib/esm/useDebounce/index.js +16 -0
- package/lib/esm/useDebugInformation/index.d.ts +8 -0
- package/lib/esm/useDebugInformation/index.js +38 -0
- package/lib/esm/useDeepCompareEffect/index.d.ts +2 -0
- package/lib/esm/useDeepCompareEffect/index.js +10 -0
- package/lib/esm/useEffectOnce/index.d.ts +1 -0
- package/lib/esm/useEffectOnce/index.js +4 -0
- package/lib/esm/useEventListener/index.d.ts +2 -0
- package/lib/esm/useEventListener/index.js +15 -0
- package/lib/esm/useFetch/index.d.ts +2 -0
- package/lib/esm/useFetch/index.js +76 -0
- package/lib/esm/useGenerateHtmlId/index.d.ts +3 -0
- package/lib/esm/useGenerateHtmlId/index.js +7 -0
- package/lib/esm/useGeolocation/index.d.ts +2 -0
- package/lib/esm/useGeolocation/index.js +23 -0
- package/lib/esm/useHover/index.d.ts +2 -0
- package/lib/esm/useHover/index.js +11 -0
- package/lib/esm/useLongPress/index.d.ts +4 -0
- package/lib/esm/useLongPress/index.js +13 -0
- package/lib/esm/useMediaQuery/index.d.ts +1 -0
- package/lib/esm/useMediaQuery/index.js +16 -0
- package/lib/esm/useOnScreen/index.d.ts +2 -0
- package/lib/esm/useOnScreen/index.js +20 -0
- package/lib/esm/useOnlineStatus/index.d.ts +1 -0
- package/lib/esm/useOnlineStatus/index.js +8 -0
- package/lib/esm/usePagination/index.d.ts +9 -0
- package/lib/esm/usePagination/index.js +19 -0
- package/lib/esm/usePrevious/index.d.ts +2 -0
- package/lib/esm/usePrevious/index.js +10 -0
- package/lib/esm/useRenderCount/index.d.ts +1 -0
- package/lib/esm/useRenderCount/index.js +8 -0
- package/lib/esm/useScript/index.d.ts +2 -0
- package/lib/esm/useScript/index.js +13 -0
- package/lib/esm/useSize/index.d.ts +3 -0
- package/lib/esm/useSize/index.js +15 -0
- package/lib/esm/useStateWithHistory/index.d.ts +4 -0
- package/lib/esm/useStateWithHistory/index.js +50 -0
- package/lib/esm/useStateWithValidation/index.d.ts +2 -0
- package/lib/esm/useStateWithValidation/index.js +11 -0
- package/lib/esm/useStorage/index.d.ts +5 -0
- package/lib/esm/useStorage/index.js +28 -0
- package/lib/esm/useTimeout/index.d.ts +2 -0
- package/lib/esm/useTimeout/index.js +23 -0
- package/lib/esm/useToggle/index.d.ts +2 -0
- package/lib/esm/useToggle/index.js +9 -0
- package/lib/esm/useUpdateEffect/index.d.ts +2 -0
- package/lib/esm/useUpdateEffect/index.js +11 -0
- package/lib/esm/useWindowSize/index.d.ts +2 -0
- package/lib/esm/useWindowSize/index.js +12 -0
- package/package.json +49 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import useEffectOnce from "../useEffectOnce";
|
|
2
|
+
import useEventListener from "../useEventListener";
|
|
3
|
+
import useTimeout from "../useTimeout";
|
|
4
|
+
export default function useLongPress(ref, cb, _a) {
|
|
5
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.delay, delay = _c === void 0 ? 250 : _c;
|
|
6
|
+
var _d = useTimeout(cb, delay), reset = _d.reset, clear = _d.clear;
|
|
7
|
+
useEffectOnce(clear);
|
|
8
|
+
useEventListener("mousedown", reset, ref.current);
|
|
9
|
+
useEventListener("touchstart", reset, ref.current);
|
|
10
|
+
useEventListener("mouseup", clear, ref.current);
|
|
11
|
+
useEventListener("mouseleave", clear, ref.current);
|
|
12
|
+
useEventListener("touchend", clear, ref.current);
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useMediaQuery(mediaQuery: string): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import useEventListener from "../useEventListener";
|
|
3
|
+
export default function useMediaQuery(mediaQuery) {
|
|
4
|
+
var _a = useState(false), isMatch = _a[0], setIsMatch = _a[1];
|
|
5
|
+
var _b = useState(undefined), mediaQueryList = _b[0], setMediaQueryList = _b[1];
|
|
6
|
+
useEffect(function () {
|
|
7
|
+
var list = window.matchMedia(mediaQuery);
|
|
8
|
+
setMediaQueryList(list);
|
|
9
|
+
setIsMatch(list.matches);
|
|
10
|
+
}, [mediaQuery]);
|
|
11
|
+
useEventListener("change", function (event) {
|
|
12
|
+
var e = event;
|
|
13
|
+
setIsMatch(e.matches);
|
|
14
|
+
}, mediaQueryList);
|
|
15
|
+
return isMatch;
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
export default function useOnScreen(ref, rootMargin) {
|
|
3
|
+
if (rootMargin === void 0) { rootMargin = "0px"; }
|
|
4
|
+
var _a = useState(false), isVisible = _a[0], setIsVisible = _a[1];
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
if (ref.current == null)
|
|
7
|
+
return;
|
|
8
|
+
var observer = new IntersectionObserver(function (_a) {
|
|
9
|
+
var entry = _a[0];
|
|
10
|
+
return setIsVisible(entry.isIntersecting);
|
|
11
|
+
}, { rootMargin: rootMargin });
|
|
12
|
+
observer.observe(ref.current);
|
|
13
|
+
return function () {
|
|
14
|
+
if (ref.current == null)
|
|
15
|
+
return;
|
|
16
|
+
observer.unobserve(ref.current);
|
|
17
|
+
};
|
|
18
|
+
}, [ref.current, rootMargin]);
|
|
19
|
+
return isVisible;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useOnlineStatus(): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import useEventListener from "../useEventListener";
|
|
3
|
+
export default function useOnlineStatus() {
|
|
4
|
+
var _a = useState(navigator.onLine), online = _a[0], setOnline = _a[1];
|
|
5
|
+
useEventListener("online", function () { return setOnline(navigator.onLine); });
|
|
6
|
+
useEventListener("offline", function () { return setOnline(navigator.onLine); });
|
|
7
|
+
return online;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface PaginationResponse {
|
|
2
|
+
data: Record<string, unknown>[];
|
|
3
|
+
totalPages: number;
|
|
4
|
+
currentPage: number;
|
|
5
|
+
nextPage: () => void;
|
|
6
|
+
previousPage: () => void;
|
|
7
|
+
}
|
|
8
|
+
export default function usePagination(data: Record<string, unknown>[], pageSize: number): PaginationResponse;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
export default function usePagination(data, pageSize) {
|
|
3
|
+
var _a = useState(0), pageIndex = _a[0], setPageIndex = _a[1];
|
|
4
|
+
var totalPages = Math.ceil(data.length / pageSize);
|
|
5
|
+
var filteredData = data.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize);
|
|
6
|
+
var nextPage = function () {
|
|
7
|
+
setPageIndex(Math.min(pageIndex + 1, totalPages - 1));
|
|
8
|
+
};
|
|
9
|
+
var previousPage = function () {
|
|
10
|
+
setPageIndex(Math.max(pageIndex - 1, 0));
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
data: filteredData,
|
|
14
|
+
currentPage: pageIndex + 1,
|
|
15
|
+
totalPages: totalPages,
|
|
16
|
+
nextPage: nextPage,
|
|
17
|
+
previousPage: previousPage,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
export default function usePrevious(value) {
|
|
3
|
+
var currentRef = useRef(value);
|
|
4
|
+
var previousRef = useRef();
|
|
5
|
+
if (currentRef.current !== value) {
|
|
6
|
+
previousRef.current = currentRef.current;
|
|
7
|
+
currentRef.current = value;
|
|
8
|
+
}
|
|
9
|
+
return previousRef.current;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useRenderCount(): number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import useAsync from "../useAsync";
|
|
2
|
+
export default function useScript(url) {
|
|
3
|
+
return useAsync(function () {
|
|
4
|
+
var script = document.createElement("script");
|
|
5
|
+
script.src = url;
|
|
6
|
+
script.async = true;
|
|
7
|
+
return new Promise(function (resolve, reject) {
|
|
8
|
+
script.addEventListener("load", resolve);
|
|
9
|
+
script.addEventListener("error", reject);
|
|
10
|
+
document.body.appendChild(script);
|
|
11
|
+
});
|
|
12
|
+
}, [url]);
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
export default function useSize(ref) {
|
|
3
|
+
var _a = useState({}), size = _a[0], setSize = _a[1];
|
|
4
|
+
useEffect(function () {
|
|
5
|
+
if (ref.current == null)
|
|
6
|
+
return;
|
|
7
|
+
var observer = new ResizeObserver(function (_a) {
|
|
8
|
+
var entry = _a[0];
|
|
9
|
+
return setSize(entry.contentRect);
|
|
10
|
+
});
|
|
11
|
+
observer.observe(ref.current);
|
|
12
|
+
return function () { return observer.disconnect(); };
|
|
13
|
+
}, []);
|
|
14
|
+
return size;
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
|
+
export default function useStateWithHistory(defaultValue, _a) {
|
|
3
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.capacity, capacity = _c === void 0 ? 10 : _c;
|
|
4
|
+
var _d = useState(defaultValue), value = _d[0], setValue = _d[1];
|
|
5
|
+
var historyRef = useRef([value]);
|
|
6
|
+
var pointerRef = useRef(0);
|
|
7
|
+
var set = useCallback(function (item) {
|
|
8
|
+
var resolvedValue = typeof item === "function" ? item(value) : item;
|
|
9
|
+
if (historyRef.current[pointerRef.current] !== resolvedValue) {
|
|
10
|
+
if (pointerRef.current < historyRef.current.length - 1) {
|
|
11
|
+
historyRef.current.splice(pointerRef.current + 1);
|
|
12
|
+
}
|
|
13
|
+
historyRef.current.push(resolvedValue);
|
|
14
|
+
while (historyRef.current.length > capacity) {
|
|
15
|
+
historyRef.current.shift();
|
|
16
|
+
}
|
|
17
|
+
pointerRef.current = historyRef.current.length - 1;
|
|
18
|
+
}
|
|
19
|
+
setValue(resolvedValue);
|
|
20
|
+
}, [capacity, value]);
|
|
21
|
+
var back = useCallback(function () {
|
|
22
|
+
if (pointerRef.current <= 0)
|
|
23
|
+
return;
|
|
24
|
+
pointerRef.current--;
|
|
25
|
+
setValue(historyRef.current[pointerRef.current]);
|
|
26
|
+
}, []);
|
|
27
|
+
var forward = useCallback(function () {
|
|
28
|
+
if (pointerRef.current >= historyRef.current.length - 1)
|
|
29
|
+
return;
|
|
30
|
+
pointerRef.current++;
|
|
31
|
+
setValue(historyRef.current[pointerRef.current]);
|
|
32
|
+
}, []);
|
|
33
|
+
var go = useCallback(function (index) {
|
|
34
|
+
if (index < 0 || index >= historyRef.current.length - 1)
|
|
35
|
+
return;
|
|
36
|
+
pointerRef.current = index;
|
|
37
|
+
setValue(historyRef.current[pointerRef.current]);
|
|
38
|
+
}, []);
|
|
39
|
+
return [
|
|
40
|
+
value,
|
|
41
|
+
set,
|
|
42
|
+
{
|
|
43
|
+
history: historyRef.current,
|
|
44
|
+
pointer: pointerRef.current,
|
|
45
|
+
back: back,
|
|
46
|
+
forward: forward,
|
|
47
|
+
go: go,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
export default function useStateWithValidation(validationFunc, initialValue) {
|
|
3
|
+
var _a = useState(initialValue), state = _a[0], setState = _a[1];
|
|
4
|
+
var _b = useState(function () { return validationFunc(state); }), isValid = _b[0], setIsValid = _b[1];
|
|
5
|
+
var onChange = useCallback(function (nextState) {
|
|
6
|
+
var value = typeof nextState === "function" ? nextState(state) : nextState;
|
|
7
|
+
setState(value);
|
|
8
|
+
setIsValid(validationFunc(value));
|
|
9
|
+
}, [validationFunc]);
|
|
10
|
+
return [state, onChange, isValid];
|
|
11
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Dispatch } from "react";
|
|
2
|
+
declare type StorageObject = [value: any, setValue: Dispatch<unknown>, remove: () => void];
|
|
3
|
+
export declare function useLocalStorage(key: string, defaultValue?: any): StorageObject;
|
|
4
|
+
export declare function useSessionStorage(key: string, defaultValue?: any): StorageObject;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { useCallback, useState, useEffect } from "react";
|
|
3
|
+
var FUNCTION = "function";
|
|
4
|
+
export function useLocalStorage(key, defaultValue) {
|
|
5
|
+
if (defaultValue === void 0) { defaultValue = ""; }
|
|
6
|
+
return useStorage(key, defaultValue, window.localStorage);
|
|
7
|
+
}
|
|
8
|
+
export function useSessionStorage(key, defaultValue) {
|
|
9
|
+
if (defaultValue === void 0) { defaultValue = ""; }
|
|
10
|
+
return useStorage(key, defaultValue, window.sessionStorage);
|
|
11
|
+
}
|
|
12
|
+
function useStorage(key, defaultValue, storageObject) {
|
|
13
|
+
var _a = useState(function () {
|
|
14
|
+
var jsonValue = storageObject.getItem(key);
|
|
15
|
+
if (jsonValue != null)
|
|
16
|
+
return JSON.parse(jsonValue);
|
|
17
|
+
return typeof defaultValue === FUNCTION ? defaultValue() : defaultValue;
|
|
18
|
+
}), value = _a[0], setValue = _a[1];
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
return storageObject.removeItem(key);
|
|
22
|
+
storageObject.setItem(key, JSON.stringify(value));
|
|
23
|
+
}, [key, value, storageObject]);
|
|
24
|
+
var remove = useCallback(function () {
|
|
25
|
+
setValue(undefined);
|
|
26
|
+
}, []);
|
|
27
|
+
return [value, setValue, remove];
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
export default function useTimeout(callback, delay) {
|
|
3
|
+
var callbackRef = useRef(callback);
|
|
4
|
+
var timeoutRef = useRef(null);
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
callbackRef.current = callback;
|
|
7
|
+
}, [callback]);
|
|
8
|
+
var set = useCallback(function () {
|
|
9
|
+
timeoutRef.current = setTimeout(function () { return callbackRef.current(); }, delay);
|
|
10
|
+
}, [delay]);
|
|
11
|
+
var clear = useCallback(function () {
|
|
12
|
+
timeoutRef.current && clearTimeout(timeoutRef.current);
|
|
13
|
+
}, []);
|
|
14
|
+
useEffect(function () {
|
|
15
|
+
set();
|
|
16
|
+
return clear;
|
|
17
|
+
}, [delay, set, clear]);
|
|
18
|
+
var reset = useCallback(function () {
|
|
19
|
+
clear();
|
|
20
|
+
set();
|
|
21
|
+
}, [clear, set]);
|
|
22
|
+
return { reset: reset, clear: clear };
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
export default function useToggle(defaultValue) {
|
|
3
|
+
if (defaultValue === void 0) { defaultValue = false; }
|
|
4
|
+
var _a = useState(defaultValue), value = _a[0], setValue = _a[1];
|
|
5
|
+
function toggleValue(newValue) {
|
|
6
|
+
setValue(function (currentValue) { return (typeof newValue === "boolean" ? newValue : !currentValue); });
|
|
7
|
+
}
|
|
8
|
+
return [value, toggleValue];
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
export default function useUpdateEffect(callback, dependencies) {
|
|
3
|
+
var firstRenderRef = useRef(true);
|
|
4
|
+
useEffect(function () {
|
|
5
|
+
if (firstRenderRef.current) {
|
|
6
|
+
firstRenderRef.current = false;
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
return callback();
|
|
10
|
+
}, dependencies);
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import useEventListener from "../useEventListener";
|
|
3
|
+
export default function useWindowSize() {
|
|
4
|
+
var _a = useState({
|
|
5
|
+
width: window.innerWidth,
|
|
6
|
+
height: window.innerHeight,
|
|
7
|
+
}), windowSize = _a[0], setWindowSize = _a[1];
|
|
8
|
+
useEventListener("resize", function () {
|
|
9
|
+
setWindowSize({ width: window.innerWidth, height: window.innerHeight });
|
|
10
|
+
});
|
|
11
|
+
return windowSize;
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@grantpearceuk/hooks",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./lib/cjs/index.js",
|
|
5
|
+
"module": "./lib/esm/index.js",
|
|
6
|
+
"types": "./lib/esm/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"release": "standard-version",
|
|
9
|
+
"test": "react-scripts test --watchAll=false",
|
|
10
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
11
|
+
"build:esm": "tsc",
|
|
12
|
+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
|
|
13
|
+
"publish-public": "npm publish --access public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@material-ui/core": "^4.12.3",
|
|
17
|
+
"@testing-library/jest-dom": "^5.14.1",
|
|
18
|
+
"@testing-library/react": "^11.2.7",
|
|
19
|
+
"@testing-library/user-event": "^12.8.3",
|
|
20
|
+
"copy-to-clipboard": "^3.3.1",
|
|
21
|
+
"js-cookie": "^3.0.1",
|
|
22
|
+
"lodash": "^4.17.21",
|
|
23
|
+
"react-scripts": "4.0.3",
|
|
24
|
+
"standard-version": "^9.5.0",
|
|
25
|
+
"web-vitals": "^1.1.2"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@testing-library/react-hooks": "^7.0.2",
|
|
29
|
+
"@types/jest": "^27.0.1",
|
|
30
|
+
"@types/js-cookie": "^3.0.0",
|
|
31
|
+
"@types/lodash": "^4.14.175",
|
|
32
|
+
"@types/react": "^17.0.21",
|
|
33
|
+
"@types/react-dom": "^17.0.9",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
35
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
36
|
+
"eslint": "^7.32.0",
|
|
37
|
+
"eslint-config-prettier": "^8.3.0",
|
|
38
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
39
|
+
"prettier": "^2.4.1",
|
|
40
|
+
"typescript": "^4.4.3"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": "^17.0.2",
|
|
44
|
+
"react-dom": "^17.0.2"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"/lib"
|
|
48
|
+
]
|
|
49
|
+
}
|