@croct/plug-react 0.11.0 → 0.11.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/hooks/useContent.cjs +8 -6
- package/hooks/useContent.js +8 -6
- package/hooks/useCroct.cjs +1 -0
- package/hooks/useCroct.js +1 -0
- package/hooks/useEvaluation.cjs +1 -0
- package/hooks/useEvaluation.js +1 -0
- package/package.json +2 -2
package/hooks/useContent.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
"use client";
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -34,12 +35,13 @@ function useCsrContent(id, options = {}) {
|
|
|
34
35
|
fallback: fallbackContent,
|
|
35
36
|
initial: initialContent,
|
|
36
37
|
staleWhileLoading = false,
|
|
38
|
+
preferredLocale,
|
|
37
39
|
...fetchOptions
|
|
38
40
|
} = options;
|
|
39
|
-
const
|
|
41
|
+
const normalizedLocale = normalizePreferredLocale(preferredLocale);
|
|
40
42
|
const defaultContent = (0, import_react.useMemo)(
|
|
41
|
-
() => (0, import_content.getSlotContent)(id,
|
|
42
|
-
[id,
|
|
43
|
+
() => (0, import_content.getSlotContent)(id, normalizedLocale) ?? void 0,
|
|
44
|
+
[id, normalizedLocale]
|
|
43
45
|
);
|
|
44
46
|
const fallback = fallbackContent === void 0 ? defaultContent : fallbackContent;
|
|
45
47
|
const [initial, setInitial] = (0, import_react.useState)(
|
|
@@ -48,12 +50,12 @@ function useCsrContent(id, options = {}) {
|
|
|
48
50
|
const croct = (0, import_useCroct.useCroct)();
|
|
49
51
|
const result = (0, import_useLoader.useLoader)({
|
|
50
52
|
cacheKey: (0, import_hash.hash)(
|
|
51
|
-
`useContent:${cacheKey ?? ""}:${id}:${
|
|
53
|
+
`useContent:${cacheKey ?? ""}:${id}:${normalizedLocale ?? ""}:${JSON.stringify(fetchOptions.attributes ?? {})}`
|
|
52
54
|
),
|
|
53
55
|
loader: () => croct.fetch(id, {
|
|
54
56
|
...fetchOptions,
|
|
55
|
-
preferredLocale,
|
|
56
|
-
fallback
|
|
57
|
+
...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
|
|
58
|
+
...fallback !== void 0 ? { fallback } : {}
|
|
57
59
|
}).then(({ content }) => content),
|
|
58
60
|
initial,
|
|
59
61
|
expiration
|
package/hooks/useContent.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { useEffect, useMemo, useState } from "react";
|
|
2
3
|
import { getSlotContent } from "@croct/content";
|
|
3
4
|
import { useLoader } from "./useLoader.js";
|
|
@@ -11,12 +12,13 @@ function useCsrContent(id, options = {}) {
|
|
|
11
12
|
fallback: fallbackContent,
|
|
12
13
|
initial: initialContent,
|
|
13
14
|
staleWhileLoading = false,
|
|
15
|
+
preferredLocale,
|
|
14
16
|
...fetchOptions
|
|
15
17
|
} = options;
|
|
16
|
-
const
|
|
18
|
+
const normalizedLocale = normalizePreferredLocale(preferredLocale);
|
|
17
19
|
const defaultContent = useMemo(
|
|
18
|
-
() => getSlotContent(id,
|
|
19
|
-
[id,
|
|
20
|
+
() => getSlotContent(id, normalizedLocale) ?? void 0,
|
|
21
|
+
[id, normalizedLocale]
|
|
20
22
|
);
|
|
21
23
|
const fallback = fallbackContent === void 0 ? defaultContent : fallbackContent;
|
|
22
24
|
const [initial, setInitial] = useState(
|
|
@@ -25,12 +27,12 @@ function useCsrContent(id, options = {}) {
|
|
|
25
27
|
const croct = useCroct();
|
|
26
28
|
const result = useLoader({
|
|
27
29
|
cacheKey: hash(
|
|
28
|
-
`useContent:${cacheKey ?? ""}:${id}:${
|
|
30
|
+
`useContent:${cacheKey ?? ""}:${id}:${normalizedLocale ?? ""}:${JSON.stringify(fetchOptions.attributes ?? {})}`
|
|
29
31
|
),
|
|
30
32
|
loader: () => croct.fetch(id, {
|
|
31
33
|
...fetchOptions,
|
|
32
|
-
preferredLocale,
|
|
33
|
-
fallback
|
|
34
|
+
...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
|
|
35
|
+
...fallback !== void 0 ? { fallback } : {}
|
|
34
36
|
}).then(({ content }) => content),
|
|
35
37
|
initial,
|
|
36
38
|
expiration
|
package/hooks/useCroct.cjs
CHANGED
package/hooks/useCroct.js
CHANGED
package/hooks/useEvaluation.cjs
CHANGED
package/hooks/useEvaluation.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@croct/plug-react",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "React components and hooks to plug your React applications into Croct.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Croct",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@croct/plug": "^0.17.
|
|
65
|
+
"@croct/plug": "^0.17.2",
|
|
66
66
|
"@croct/sdk": "^0.18.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|