@reactables/react 1.3.0-alpha.2 → 1.3.0-beta.0
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Reactable } from '@reactables/core';
|
|
3
|
-
export declare const StoreContext: React.Context<Reactable<unknown, unknown
|
|
3
|
+
export declare const StoreContext: React.Context<Reactable<unknown, unknown, Record<string, string>>>;
|
|
4
4
|
interface StoreProviderProps<T, S> {
|
|
5
5
|
rxStore: Reactable<T, S>;
|
|
6
6
|
children?: React.ReactNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { Reactable, Action } from '@reactables/core';
|
|
3
3
|
export type HookedReactable<T, S> = [T, S, Observable<T>, Observable<Action<unknown>>?];
|
|
4
|
-
export declare const useReactable: <T, S, U extends unknown[]>(reactableFactory: (...props: U) => Reactable<T, S
|
|
4
|
+
export declare const useReactable: <T, S, U extends unknown[]>(reactableFactory: (...props: U) => Reactable<T, S, Record<string, string>>, ...props: U) => HookedReactable<T, S>;
|
package/dist/index.js
CHANGED
|
@@ -19,23 +19,25 @@ 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
|
|
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];
|
|
23
33
|
var _b = React.useState(), state = _b[0], setState = _b[1];
|
|
24
34
|
React.useEffect(function () {
|
|
25
35
|
var subscription = state$.subscribe(function (result) {
|
|
26
36
|
setState(result);
|
|
27
37
|
});
|
|
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
|
-
};
|
|
38
|
+
return function () { return subscription.unsubscribe(); };
|
|
37
39
|
}, [state$]);
|
|
38
|
-
return [state, actions, state$,
|
|
40
|
+
return [state, actions, state$, actions$];
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
var useAppStore = function () {
|
package/package.json
CHANGED