@cripty2001/utils 0.0.146 → 0.0.147

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.
@@ -36,11 +36,18 @@ const Searcher_1 = require("./Searcher");
36
36
  function useWhisprValue(w, computer = (d) => d) {
37
37
  const value_w = (0, react_1.useRef)(whispr_1.Whispr.from({ w }, ({ w }) => computer(w))).current;
38
38
  const [value, setValue] = (0, react_1.useState)(value_w.value);
39
- value_w.subscribe((newValue) => {
40
- if ((0, lodash_1.isEqual)(newValue, value))
41
- return;
42
- setValue(newValue);
43
- }, false); // Already got the initial value, and this will call syncronously generate a react warning as called on an not yet mounted component
39
+ const valueRef = (0, react_1.useRef)(value);
40
+ (0, react_1.useEffect)(() => {
41
+ valueRef.current = value;
42
+ }, [value]);
43
+ (0, react_1.useEffect)(() => {
44
+ const unsub = value_w.subscribe((newValue) => {
45
+ if ((0, lodash_1.isEqual)(newValue, valueRef.current))
46
+ return;
47
+ setValue(newValue);
48
+ }, false);
49
+ return () => unsub();
50
+ }, [value_w]);
44
51
  return value;
45
52
  }
46
53
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.146",
3
+ "version": "0.0.147",
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": {