@swan-io/shared-business 8.4.3 → 8.4.4

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": "@swan-io/shared-business",
3
- "version": "8.4.3",
3
+ "version": "8.4.4",
4
4
  "engines": {
5
5
  "node": ">=20.9.0",
6
6
  "yarn": "^1.22.0"
@@ -1,4 +1,5 @@
1
- import { PKClient } from "@placekit/client-js";
2
- export declare const usePlacekit: ({ apiKey }: {
1
+ import type { PKClient } from "@placekit/client-js/lite";
2
+ export declare const usePlacekit: ({ apiKey, debounceInterval, }: {
3
3
  apiKey?: string;
4
+ debounceInterval?: number;
4
5
  }) => PKClient | undefined;
@@ -1,12 +1,29 @@
1
- import { useEffect, useState } from "react";
2
- export const usePlacekit = ({ apiKey }) => {
3
- const [placekit, setPlacekit] = useState(undefined);
1
+ import { useEffect, useMemo, useState } from "react";
2
+ const debounce = (fn, ms) => {
3
+ let timer;
4
+ return (...args) => {
5
+ clearTimeout(timer);
6
+ return new Promise(resolve => {
7
+ timer = setTimeout(() => resolve(fn(...args)), ms);
8
+ });
9
+ };
10
+ };
11
+ export const usePlacekit = ({ apiKey, debounceInterval = 1000, }) => {
12
+ const [client, setClient] = useState();
4
13
  useEffect(() => {
5
14
  if (apiKey != null) {
6
- void import("@placekit/client-js").then(({ default: placekit }) => {
7
- setPlacekit(placekit(apiKey));
15
+ void import("@placekit/client-js/lite").then(({ default: placekit }) => {
16
+ setClient(placekit(apiKey));
8
17
  });
9
18
  }
10
19
  }, [apiKey]);
11
- return placekit;
20
+ return useMemo(() => {
21
+ if (client != null) {
22
+ return {
23
+ ...client,
24
+ search: debounce(client.search, debounceInterval),
25
+ reverse: debounce(client.reverse, debounceInterval),
26
+ };
27
+ }
28
+ }, [client, debounceInterval]);
12
29
  };