@croct/plug-react 0.11.0 → 0.11.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.
@@ -34,12 +34,13 @@ function useCsrContent(id, options = {}) {
34
34
  fallback: fallbackContent,
35
35
  initial: initialContent,
36
36
  staleWhileLoading = false,
37
+ preferredLocale,
37
38
  ...fetchOptions
38
39
  } = options;
39
- const preferredLocale = normalizePreferredLocale(fetchOptions.preferredLocale);
40
+ const normalizedLocale = normalizePreferredLocale(preferredLocale);
40
41
  const defaultContent = (0, import_react.useMemo)(
41
- () => (0, import_content.getSlotContent)(id, preferredLocale) ?? void 0,
42
- [id, preferredLocale]
42
+ () => (0, import_content.getSlotContent)(id, normalizedLocale) ?? void 0,
43
+ [id, normalizedLocale]
43
44
  );
44
45
  const fallback = fallbackContent === void 0 ? defaultContent : fallbackContent;
45
46
  const [initial, setInitial] = (0, import_react.useState)(
@@ -48,12 +49,12 @@ function useCsrContent(id, options = {}) {
48
49
  const croct = (0, import_useCroct.useCroct)();
49
50
  const result = (0, import_useLoader.useLoader)({
50
51
  cacheKey: (0, import_hash.hash)(
51
- `useContent:${cacheKey ?? ""}:${id}:${preferredLocale ?? ""}:${JSON.stringify(fetchOptions.attributes ?? {})}`
52
+ `useContent:${cacheKey ?? ""}:${id}:${normalizedLocale ?? ""}:${JSON.stringify(fetchOptions.attributes ?? {})}`
52
53
  ),
53
54
  loader: () => croct.fetch(id, {
54
55
  ...fetchOptions,
55
- preferredLocale,
56
- fallback
56
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
57
+ ...fallback !== void 0 ? { fallback } : {}
57
58
  }).then(({ content }) => content),
58
59
  initial,
59
60
  expiration
@@ -11,12 +11,13 @@ function useCsrContent(id, options = {}) {
11
11
  fallback: fallbackContent,
12
12
  initial: initialContent,
13
13
  staleWhileLoading = false,
14
+ preferredLocale,
14
15
  ...fetchOptions
15
16
  } = options;
16
- const preferredLocale = normalizePreferredLocale(fetchOptions.preferredLocale);
17
+ const normalizedLocale = normalizePreferredLocale(preferredLocale);
17
18
  const defaultContent = useMemo(
18
- () => getSlotContent(id, preferredLocale) ?? void 0,
19
- [id, preferredLocale]
19
+ () => getSlotContent(id, normalizedLocale) ?? void 0,
20
+ [id, normalizedLocale]
20
21
  );
21
22
  const fallback = fallbackContent === void 0 ? defaultContent : fallbackContent;
22
23
  const [initial, setInitial] = useState(
@@ -25,12 +26,12 @@ function useCsrContent(id, options = {}) {
25
26
  const croct = useCroct();
26
27
  const result = useLoader({
27
28
  cacheKey: hash(
28
- `useContent:${cacheKey ?? ""}:${id}:${preferredLocale ?? ""}:${JSON.stringify(fetchOptions.attributes ?? {})}`
29
+ `useContent:${cacheKey ?? ""}:${id}:${normalizedLocale ?? ""}:${JSON.stringify(fetchOptions.attributes ?? {})}`
29
30
  ),
30
31
  loader: () => croct.fetch(id, {
31
32
  ...fetchOptions,
32
- preferredLocale,
33
- fallback
33
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
34
+ ...fallback !== void 0 ? { fallback } : {}
34
35
  }).then(({ content }) => content),
35
36
  initial,
36
37
  expiration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/plug-react",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
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.1",
65
+ "@croct/plug": "^0.17.2",
66
66
  "@croct/sdk": "^0.18.0"
67
67
  },
68
68
  "devDependencies": {