@cripty2001/utils 0.0.140 → 0.0.141

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.
@@ -79,3 +79,10 @@ export declare function useRelTime(refresh?: number): (ts: Date | number) => str
79
79
  *
80
80
  */
81
81
  export declare function useSearcher<T>(data: SearcherData<T>[], q: string): SearcherData<T>[];
82
+ /**
83
+ * A react ref hook with safe laxy initialization, ready for safe effects.
84
+ * @remarks The initialization function will only be called once, and the result will be stored in the ref.
85
+ * @param value The value to initialize the ref with. If a function is provided, it will be called to initialize the ref.
86
+ * @returns
87
+ */
88
+ export declare function useSafeRef<T>(value: (() => T)): T;
@@ -9,6 +9,7 @@ exports.useSynced = useSynced;
9
9
  exports.useAsync = useAsync;
10
10
  exports.useRelTime = useRelTime;
11
11
  exports.useSearcher = useSearcher;
12
+ exports.useSafeRef = useSafeRef;
12
13
  const whispr_1 = require("@cripty2001/whispr");
13
14
  const react_1 = require("react");
14
15
  const lodash_1 = require("lodash");
@@ -234,3 +235,18 @@ function useSearcher(data, q) {
234
235
  const searcher = (0, Searcher_1.useSearcher_w)(data_w, q_w);
235
236
  return useWhisprValue(searcher);
236
237
  }
238
+ /**
239
+ * A react ref hook with safe laxy initialization, ready for safe effects.
240
+ * @remarks The initialization function will only be called once, and the result will be stored in the ref.
241
+ * @param value The value to initialize the ref with. If a function is provided, it will be called to initialize the ref.
242
+ * @returns
243
+ */
244
+ function useSafeRef(value) {
245
+ const ref = (0, react_1.useRef)(null);
246
+ (0, react_1.useEffect)(() => {
247
+ if (ref.current !== null)
248
+ return;
249
+ ref.current = value();
250
+ }, []);
251
+ return ref.current;
252
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.140",
3
+ "version": "0.0.141",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {