@openmrs/esm-react-utils 5.1.1-pre.997 → 5.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "5.1.1-pre.997",
3
+ "version": "5.2.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "React utilities for OpenMRS.",
6
6
  "browser": "dist/openmrs-esm-react-utils.js",
@@ -40,8 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "lodash-es": "^4.17.21",
43
- "single-spa-react": "~5.0.0",
44
- "swr": "^2.0.1"
43
+ "single-spa-react": "~5.0.0"
45
44
  },
46
45
  "peerDependencies": {
47
46
  "@openmrs/esm-api": "5.x",
@@ -53,22 +52,24 @@
53
52
  "i18next": "19.x",
54
53
  "react": "18.x",
55
54
  "react-dom": "18.x",
56
- "react-i18next": "11.x"
55
+ "react-i18next": "11.x",
56
+ "swr": "2.x"
57
57
  },
58
58
  "devDependencies": {
59
- "@openmrs/esm-api": "^5.1.1-pre.997",
60
- "@openmrs/esm-config": "^5.1.1-pre.997",
61
- "@openmrs/esm-error-handling": "^5.1.1-pre.997",
62
- "@openmrs/esm-extensions": "^5.1.1-pre.997",
63
- "@openmrs/esm-feature-flags": "^5.1.1-pre.997",
64
- "@openmrs/esm-globals": "^5.1.1-pre.997",
59
+ "@openmrs/esm-api": "^5.2.0",
60
+ "@openmrs/esm-config": "^5.2.0",
61
+ "@openmrs/esm-error-handling": "^5.2.0",
62
+ "@openmrs/esm-extensions": "^5.2.0",
63
+ "@openmrs/esm-feature-flags": "^5.2.0",
64
+ "@openmrs/esm-globals": "^5.2.0",
65
65
  "dayjs": "^1.10.8",
66
66
  "i18next": "^19.6.0",
67
67
  "react": "^18.1.0",
68
68
  "react-dom": "^18.1.0",
69
69
  "react-i18next": "^11.16.9",
70
70
  "rxjs": "^6.5.3",
71
+ "swr": "^2.2.2",
71
72
  "webpack": "^5.88.0"
72
73
  },
73
- "gitHead": "e178ff32e60aa9de9d889e292a3d320ff7d16906"
74
+ "gitHead": "f46cd16443cae13069a55067ca317ac995eef570"
74
75
  }
package/src/index.ts CHANGED
@@ -26,3 +26,4 @@ export * from "./useStore";
26
26
  export * from "./useVisit";
27
27
  export * from "./useVisitTypes";
28
28
  export * from "./usePagination";
29
+ export * from "./useDebounce";
package/src/public.ts CHANGED
@@ -22,3 +22,4 @@ export * from "./useStore";
22
22
  export * from "./useVisit";
23
23
  export * from "./useVisitTypes";
24
24
  export * from "./usePagination";
25
+ export * from "./useDebounce";
@@ -0,0 +1,43 @@
1
+ /** @module @category API */
2
+ import { useEffect, useState } from "react";
3
+
4
+ /**
5
+ * This hook debounces a state variable. That state variable can then be used as the
6
+ * value of a controlled input, while the return value of this hook is used for making
7
+ * a request.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { useDebounce } from "@openmrs/esm-react-utils";
12
+ *
13
+ * function MyComponent() {
14
+ * const [searchTerm, setSearchTerm] = useState('');
15
+ * const debouncedSearchTerm = useDebounce(searchTerm);
16
+ * const swrResult = useSWR(`/api/search?q=${debouncedSearchTerm}`)
17
+ *
18
+ * return (
19
+ * <Search
20
+ * labelText={t('search', 'Search')}
21
+ * onChange={(e) => setSearchTerm(e.target.value)}
22
+ * value={searchTerm}
23
+ * />
24
+ * )
25
+ * }
26
+ * ```
27
+ *
28
+ * @param value The value that will be used to set `debounceValue`
29
+ * @param delay The number of milliseconds to wait before updating `debounceValue`
30
+ * @returns The debounced value
31
+ */
32
+ export function useDebounce<T>(value: T, delay: number = 300) {
33
+ const [debounceValue, setDebounceValue] = useState<T>(value);
34
+ useEffect(() => {
35
+ const timer = setTimeout(() => {
36
+ setDebounceValue(value);
37
+ }, delay);
38
+ return () => {
39
+ clearTimeout(timer);
40
+ };
41
+ }, [value, delay]);
42
+ return debounceValue;
43
+ }
@@ -1,9 +0,0 @@
1
- /**
2
- * @license React
3
- * use-sync-external-store-shim.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */