@mearie/react 0.3.4 → 0.3.5
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.
- package/dist/index.cjs +8 -4
- package/dist/index.mjs +8 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,10 +30,13 @@ const useQuery = ((query, variables, options) => {
|
|
|
30
30
|
const initialized = (0, react.useRef)(false);
|
|
31
31
|
const stableVariables = (0, react.useMemo)(() => (0, _mearie_core.stringify)(variables), [variables]);
|
|
32
32
|
const stableOptions = (0, react.useMemo)(() => options, [options?.skip]);
|
|
33
|
-
const execute = (0, react.useCallback)(() => {
|
|
33
|
+
const execute = (0, react.useCallback)((force = false) => {
|
|
34
34
|
unsubscribe.current?.();
|
|
35
|
-
if (stableOptions?.skip)
|
|
36
|
-
|
|
35
|
+
if (!force && stableOptions?.skip) {
|
|
36
|
+
setLoading(false);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (initialized.current || !options?.initialData) setLoading(true);
|
|
37
40
|
initialized.current = true;
|
|
38
41
|
setError(void 0);
|
|
39
42
|
unsubscribe.current = (0, _mearie_core_stream.pipe)(client.executeQuery(query, variables, stableOptions), (0, _mearie_core_stream.subscribe)({ next: (result) => {
|
|
@@ -53,6 +56,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
53
56
|
stableVariables,
|
|
54
57
|
stableOptions
|
|
55
58
|
]);
|
|
59
|
+
const refetch = (0, react.useCallback)(() => execute(true), [execute]);
|
|
56
60
|
(0, react.useEffect)(() => {
|
|
57
61
|
execute();
|
|
58
62
|
return () => unsubscribe.current?.();
|
|
@@ -62,7 +66,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
62
66
|
loading,
|
|
63
67
|
error,
|
|
64
68
|
metadata,
|
|
65
|
-
refetch
|
|
69
|
+
refetch
|
|
66
70
|
};
|
|
67
71
|
});
|
|
68
72
|
|
package/dist/index.mjs
CHANGED
|
@@ -31,10 +31,13 @@ const useQuery = ((query, variables, options) => {
|
|
|
31
31
|
const initialized = useRef(false);
|
|
32
32
|
const stableVariables = useMemo(() => stringify(variables), [variables]);
|
|
33
33
|
const stableOptions = useMemo(() => options, [options?.skip]);
|
|
34
|
-
const execute = useCallback(() => {
|
|
34
|
+
const execute = useCallback((force = false) => {
|
|
35
35
|
unsubscribe.current?.();
|
|
36
|
-
if (stableOptions?.skip)
|
|
37
|
-
|
|
36
|
+
if (!force && stableOptions?.skip) {
|
|
37
|
+
setLoading(false);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (initialized.current || !options?.initialData) setLoading(true);
|
|
38
41
|
initialized.current = true;
|
|
39
42
|
setError(void 0);
|
|
40
43
|
unsubscribe.current = pipe(client.executeQuery(query, variables, stableOptions), subscribe({ next: (result) => {
|
|
@@ -54,6 +57,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
54
57
|
stableVariables,
|
|
55
58
|
stableOptions
|
|
56
59
|
]);
|
|
60
|
+
const refetch = useCallback(() => execute(true), [execute]);
|
|
57
61
|
useEffect(() => {
|
|
58
62
|
execute();
|
|
59
63
|
return () => unsubscribe.current?.();
|
|
@@ -63,7 +67,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
63
67
|
loading,
|
|
64
68
|
error,
|
|
65
69
|
metadata,
|
|
66
|
-
refetch
|
|
70
|
+
refetch
|
|
67
71
|
};
|
|
68
72
|
});
|
|
69
73
|
|