@cmssy/react 0.2.1 → 0.2.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/dist/client.cjs +6 -4
- package/dist/client.js +6 -4
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -1097,8 +1097,9 @@ function matchVariant(variants, selections) {
|
|
|
1097
1097
|
function ProductComponent({ content }) {
|
|
1098
1098
|
const c = content;
|
|
1099
1099
|
const { fetchProduct, addToCart } = useCart();
|
|
1100
|
-
const
|
|
1101
|
-
const [
|
|
1100
|
+
const injected = c.product ?? null;
|
|
1101
|
+
const [product, setProduct] = react.useState(injected);
|
|
1102
|
+
const [loading, setLoading] = react.useState(!injected && Boolean(c.slug));
|
|
1102
1103
|
const [selections, setSelections] = react.useState({});
|
|
1103
1104
|
const [adding, setAdding] = react.useState(false);
|
|
1104
1105
|
const [added, setAdded] = react.useState(false);
|
|
@@ -1107,11 +1108,12 @@ function ProductComponent({ content }) {
|
|
|
1107
1108
|
const slugField = c.slugField ?? "slug";
|
|
1108
1109
|
const slug = c.slug ?? "";
|
|
1109
1110
|
react.useEffect(() => {
|
|
1111
|
+
if (injected || !slug) return;
|
|
1110
1112
|
let active = true;
|
|
1111
1113
|
setLoading(true);
|
|
1112
1114
|
void (async () => {
|
|
1113
1115
|
try {
|
|
1114
|
-
const result =
|
|
1116
|
+
const result = await fetchProduct(modelSlug, { [slugField]: slug });
|
|
1115
1117
|
if (active) setProduct(result);
|
|
1116
1118
|
} finally {
|
|
1117
1119
|
if (active) setLoading(false);
|
|
@@ -1120,7 +1122,7 @@ function ProductComponent({ content }) {
|
|
|
1120
1122
|
return () => {
|
|
1121
1123
|
active = false;
|
|
1122
1124
|
};
|
|
1123
|
-
}, [fetchProduct, modelSlug, slugField, slug]);
|
|
1125
|
+
}, [injected, fetchProduct, modelSlug, slugField, slug]);
|
|
1124
1126
|
const axes = react.useMemo(
|
|
1125
1127
|
() => product ? deriveAxes(product.variants) : [],
|
|
1126
1128
|
[product]
|
package/dist/client.js
CHANGED
|
@@ -1095,8 +1095,9 @@ function matchVariant(variants, selections) {
|
|
|
1095
1095
|
function ProductComponent({ content }) {
|
|
1096
1096
|
const c = content;
|
|
1097
1097
|
const { fetchProduct, addToCart } = useCart();
|
|
1098
|
-
const
|
|
1099
|
-
const [
|
|
1098
|
+
const injected = c.product ?? null;
|
|
1099
|
+
const [product, setProduct] = useState(injected);
|
|
1100
|
+
const [loading, setLoading] = useState(!injected && Boolean(c.slug));
|
|
1100
1101
|
const [selections, setSelections] = useState({});
|
|
1101
1102
|
const [adding, setAdding] = useState(false);
|
|
1102
1103
|
const [added, setAdded] = useState(false);
|
|
@@ -1105,11 +1106,12 @@ function ProductComponent({ content }) {
|
|
|
1105
1106
|
const slugField = c.slugField ?? "slug";
|
|
1106
1107
|
const slug = c.slug ?? "";
|
|
1107
1108
|
useEffect(() => {
|
|
1109
|
+
if (injected || !slug) return;
|
|
1108
1110
|
let active = true;
|
|
1109
1111
|
setLoading(true);
|
|
1110
1112
|
void (async () => {
|
|
1111
1113
|
try {
|
|
1112
|
-
const result =
|
|
1114
|
+
const result = await fetchProduct(modelSlug, { [slugField]: slug });
|
|
1113
1115
|
if (active) setProduct(result);
|
|
1114
1116
|
} finally {
|
|
1115
1117
|
if (active) setLoading(false);
|
|
@@ -1118,7 +1120,7 @@ function ProductComponent({ content }) {
|
|
|
1118
1120
|
return () => {
|
|
1119
1121
|
active = false;
|
|
1120
1122
|
};
|
|
1121
|
-
}, [fetchProduct, modelSlug, slugField, slug]);
|
|
1123
|
+
}, [injected, fetchProduct, modelSlug, slugField, slug]);
|
|
1122
1124
|
const axes = useMemo(
|
|
1123
1125
|
() => product ? deriveAxes(product.variants) : [],
|
|
1124
1126
|
[product]
|