@prismicio/react 2.0.0-beta.8 → 2.0.2
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/README.md +2 -2
- package/dist/index.cjs +17 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +890 -891
- package/dist/index.js +17 -23
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/PrismicLink.tsx +8 -21
- package/src/PrismicProvider.tsx +2 -2
- package/src/PrismicRichText.tsx +9 -9
- package/src/PrismicToolbar.tsx +1 -1
- package/src/useStatefulPrismicClientMethod.ts +27 -25
|
@@ -71,24 +71,6 @@ export type HookOnlyParameters = {
|
|
|
71
71
|
skip?: boolean;
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
const getParamHookDependencies = (
|
|
75
|
-
params: NonNullable<ClientMethodParameters<"get">[0]>,
|
|
76
|
-
) => {
|
|
77
|
-
return [
|
|
78
|
-
params.ref,
|
|
79
|
-
params.lang,
|
|
80
|
-
params.page,
|
|
81
|
-
params.after,
|
|
82
|
-
params.fetch,
|
|
83
|
-
params.pageSize,
|
|
84
|
-
params.orderings,
|
|
85
|
-
params.fetchLinks,
|
|
86
|
-
params.graphQuery,
|
|
87
|
-
params.predicates,
|
|
88
|
-
params.accessToken,
|
|
89
|
-
];
|
|
90
|
-
};
|
|
91
|
-
|
|
92
74
|
/**
|
|
93
75
|
* Determines if a value is a `@prismicio/client` params object.
|
|
94
76
|
*
|
|
@@ -157,8 +139,13 @@ export const useStatefulPrismicClientMethod = <
|
|
|
157
139
|
|
|
158
140
|
React.useEffect(
|
|
159
141
|
() => {
|
|
142
|
+
// Used to prevent dispatching an action if the hook was cleaned up.
|
|
143
|
+
let didCancel = false;
|
|
144
|
+
|
|
160
145
|
if (!skip) {
|
|
161
|
-
|
|
146
|
+
if (!didCancel) {
|
|
147
|
+
dispatch(["start"]);
|
|
148
|
+
}
|
|
162
149
|
|
|
163
150
|
client[methodName]
|
|
164
151
|
.call(
|
|
@@ -167,20 +154,35 @@ export const useStatefulPrismicClientMethod = <
|
|
|
167
154
|
...argsWithoutParams,
|
|
168
155
|
params,
|
|
169
156
|
)
|
|
170
|
-
.then((result) =>
|
|
171
|
-
|
|
157
|
+
.then((result) => {
|
|
158
|
+
if (!didCancel) {
|
|
159
|
+
dispatch(["succeed", result as TData]);
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
.catch((error) => {
|
|
163
|
+
if (!didCancel) {
|
|
164
|
+
dispatch(["fail", error]);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
172
167
|
}
|
|
168
|
+
|
|
169
|
+
// Ensure we don't dispatch an action if the hook is cleaned up.
|
|
170
|
+
() => {
|
|
171
|
+
didCancel = true;
|
|
172
|
+
};
|
|
173
173
|
},
|
|
174
|
-
// We must disable exhaustive-deps
|
|
174
|
+
// We must disable exhaustive-deps since we are using
|
|
175
|
+
// JSON.stringify on params (effectively a deep equality check).
|
|
176
|
+
// We want this effect to run again anytime params change.
|
|
175
177
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
176
178
|
[
|
|
177
179
|
client,
|
|
178
|
-
skip,
|
|
179
180
|
methodName,
|
|
181
|
+
skip,
|
|
180
182
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
181
|
-
|
|
183
|
+
JSON.stringify(argsWithoutParams),
|
|
182
184
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
183
|
-
|
|
185
|
+
JSON.stringify(params),
|
|
184
186
|
],
|
|
185
187
|
);
|
|
186
188
|
|