eddev 2.0.0-beta.123 → 2.0.0-beta.124

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.
@@ -39,11 +39,7 @@ export type SearchParamAPI<T> = {
39
39
  */
40
40
  reset(): void;
41
41
  /**
42
- * Gets the current value of a parameter.
43
- *
44
- * In most cases, you should use the `params` object returned from `useSearchParams` instead of this method.
45
- *
46
- * However, this method will always return the current value of the parameter, even if it has been updated since the last render.
42
+ * Gets the current value of a parameter. In most cases, you should use the `params` object returned from `useSearchParams` instead of this method.
47
43
  */
48
44
  get<K extends keyof T>(key: K): T[K];
49
45
  };
@@ -51,6 +47,7 @@ export type SearchParamAPI<T> = {
51
47
  * Provides type-safe read/write access to query string parameters, integrating with the routing system.
52
48
  *
53
49
  * - Call `useSearchParams` with a default value object, which defines the expected shape of the query string parameters.
50
+ * - Only keys that are present in the default value object will be handled, and all others will be ignored.
54
51
  * - Arrays of values are supported, and you should use a default value of `[]` for that key. You may want to cast the default parameter as an array of the expected type (eg. `myValue: [] as string[]`) to ensure that the parameter type is correct.
55
52
  * - This hook returns a tuple with the current query string parameters object, and an API object with methods to interact with the query string. See {@link SearchParamAPI} for more details.
56
53
  *
@@ -7,6 +7,7 @@ import { hash } from "object-code";
7
7
  * Provides type-safe read/write access to query string parameters, integrating with the routing system.
8
8
  *
9
9
  * - Call `useSearchParams` with a default value object, which defines the expected shape of the query string parameters.
10
+ * - Only keys that are present in the default value object will be handled, and all others will be ignored.
10
11
  * - Arrays of values are supported, and you should use a default value of `[]` for that key. You may want to cast the default parameter as an array of the expected type (eg. `myValue: [] as string[]`) to ensure that the parameter type is correct.
11
12
  * - This hook returns a tuple with the current query string parameters object, and an API object with methods to interact with the query string. See {@link SearchParamAPI} for more details.
12
13
  *
@@ -46,6 +47,9 @@ export function useSearchParams(defaultValue) {
46
47
  }), [route.query]);
47
48
  const values = useRef(merged);
48
49
  values.current = merged;
50
+ // Memoized setters
51
+ const setters = useMemo(() => ({}), []);
52
+ // Gets the current value, directly from the source.
49
53
  function get() {
50
54
  if (env.client) {
51
55
  return { ...defaultValue, ...parseQuery(document.location.search) };
@@ -54,6 +58,7 @@ export function useSearchParams(defaultValue) {
54
58
  return merged;
55
59
  }
56
60
  }
61
+ // Main update function
57
62
  const update = (patch) => {
58
63
  const value = { ...get(), ...patch };
59
64
  for (let key in defaultValue) {
@@ -64,15 +69,21 @@ export function useSearchParams(defaultValue) {
64
69
  values.current = value;
65
70
  replaceQuery(value);
66
71
  };
67
- const api = useMemo(() => ({
68
- set: (key, value) => update({ [key]: value }),
69
- setAll: (value) => update({
70
- ...defaultValue,
71
- ...value,
72
- }),
73
- setter: (key) => (value) => update({ [key]: value }),
74
- reset: () => update({}),
75
- get: (key) => values.current[key],
76
- }), []);
77
- return [values.current, api];
72
+ return [
73
+ values.current,
74
+ useMemo(() => ({
75
+ set: (key, value) => update({ [key]: value }),
76
+ setAll: (value) => update({
77
+ ...defaultValue,
78
+ ...value,
79
+ }),
80
+ setter: (key) => {
81
+ if (!setters[key])
82
+ setters[key] = (value) => update({ [key]: value });
83
+ return setters[key];
84
+ },
85
+ reset: () => update({}),
86
+ get: (key) => values.current[key],
87
+ }), []),
88
+ ];
78
89
  }
@@ -1 +1 @@
1
- export declare const VERSION = "2.0.0-beta.123";
1
+ export declare const VERSION = "2.0.0-beta.124";
@@ -1 +1 @@
1
- export const VERSION = "2.0.0-beta.123";
1
+ export const VERSION = "2.0.0-beta.124";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "2.0.0-beta.123",
3
+ "version": "2.0.0-beta.124",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",