@reactables/react 1.2.1 → 1.3.0-alpha.1

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.
Files changed (2) hide show
  1. package/dist/index.js +11 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19,25 +19,23 @@ var useReactable = function (reactableFactory) {
19
19
  for (var _i = 1; _i < arguments.length; _i++) {
20
20
  props[_i - 1] = arguments[_i];
21
21
  }
22
- var rx = React.useRef(null);
23
- /**
24
- * React Strict Mode has bugs with clean up with refs so it breaks the useReactable hook as of now
25
- * See Bug: https://github.com/facebook/react/issues/26315
26
- * See Bug: https://github.com/facebook/react/issues/24670
27
- * Using this recommended approach for resolving Strict Modeissue: https://react.dev/reference/react/useRef#avoiding-recreating-the-ref-contents
28
- */
29
- if (rx.current === null) {
30
- rx.current = reactableFactory.apply(void 0, props);
31
- }
32
- var _a = rx.current, state$ = _a[0], actions = _a[1], actions$ = _a[2];
22
+ var _a = React.useMemo(function () { return reactableFactory.apply(void 0, props); }, []), state$ = _a[0], actions = _a[1], messages$ = _a[2];
33
23
  var _b = React.useState(), state = _b[0], setState = _b[1];
34
24
  React.useEffect(function () {
35
25
  var subscription = state$.subscribe(function (result) {
36
26
  setState(result);
37
27
  });
38
- return function () { return subscription.unsubscribe(); };
28
+ return function () {
29
+ // Adding setTimeout fixes the issue.
30
+ // React Strict Mode has bugs with clean up with refs so it breaks the useReactable hook as of now
31
+ // See Bug: https://github.com/facebook/react/issues/26315
32
+ // See Bug: https://github.com/facebook/react/issues/24670
33
+ setTimeout(function () {
34
+ subscription.unsubscribe();
35
+ }, 0);
36
+ };
39
37
  }, [state$]);
40
- return [state, actions, state$, actions$];
38
+ return [state, actions, state$, messages$];
41
39
  };
42
40
 
43
41
  var useAppStore = function () {
package/package.json CHANGED
@@ -17,5 +17,5 @@
17
17
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
18
18
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
19
19
  },
20
- "version": "1.2.1"
20
+ "version": "1.3.0-alpha.1"
21
21
  }