@oaiz/app-kit 0.1.4130 → 0.1.4156

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": "@oaiz/app-kit",
3
- "version": "0.1.4130",
3
+ "version": "0.1.4156",
4
4
  "description": "Source components, hooks and theme for apps built on OAIZ, to copy and change",
5
5
  "keywords": [
6
6
  "oaiz",
@@ -25,23 +25,28 @@ export type UrlStateOptions = {
25
25
 
26
26
  /**
27
27
  * One value in the page address, read and set like `useState`, so that a reload and Back keep it
28
- * and a link shares it. The address leaves out a value equal to `initial`.
28
+ * and a link shares it. The address leaves out a value equal to `initial`. The setter's optional
29
+ * second argument updates related keys in the same navigation; `null` removes a key.
29
30
  */
30
31
  export function useUrlState(
31
32
  key: string,
32
33
  initial = '',
33
34
  options: UrlStateOptions = {},
34
- ): [string, (next: string) => void] {
35
+ ): [string, (next: string, related?: Record<string, string | null>) => void] {
35
36
  const history = options.history ?? 'replace';
36
37
  const value = useSyncExternalStore(
37
38
  subscribe,
38
39
  () => new URLSearchParams(window.location.search).get(key) ?? initial,
39
40
  );
40
41
  const set = useCallback(
41
- (next: string) => {
42
+ (next: string, related: Record<string, string | null> = {}) => {
42
43
  // Values set while a push waits for its transition join that push, so one click that sets
43
44
  // two values makes one history entry holding both.
44
45
  const url = new URL((pending ?? window.location).href);
46
+ for (const [relatedKey, relatedValue] of Object.entries(related)) {
47
+ if (relatedValue === null) url.searchParams.delete(relatedKey);
48
+ else url.searchParams.set(relatedKey, relatedValue);
49
+ }
45
50
  if (next === initial) url.searchParams.delete(key);
46
51
  else url.searchParams.set(key, next);
47
52
  if (pending) {