因此,对于Beta版本,我将按以下方式指定我的缓存:
withData.js
const cache = new InMemoryCache().restore(initialState || {});
const data = {
cartOpen: false,
items: [
{
id: "ck0e27onl00av071035uzliqt",
color: {
id: "cjrumlijl003708947wpq15kp",
label: "Military Green",
name: "militarygreen",
__typename: "Color"
},
description: "Push Up Low Waist Padded Swimwear.",
mainDescription: "Bikinis Women Swimsuit 2017 Summer Beach Wear Bikini Set Push Up Swimwear Bandage Bathing Suit.",
image: "/static/white-black-01.jpg",
largeImage: "/static/white-black-01.jpg",
itemvariants: [{
id: "1234",
__typename: 'ItemVariants',
}],
price: 3500,
quantity: 0,
size: {
id: "cjrumlijl003708947wpq15kp",
label: "Medium",
name: "M",
__typename: "Size"
},
title: "Bandage Black & White Swimsuit.",
user: {
id: "cjo7q048b000408312h9c2fo0",
__typename: "User"
},
__typename: "Item"
}
]
};
cache.writeData({ data });
client_.onResetStore(() => cache.writeData({ data }));
,然后按如下所示调用localState:
items.js
const LOCAL_STATE_QUERY = gql`
query {
items @client {
id
color {
id
label
name
}
description
mainDescription
image
largeImage
itemvariants {
id
}
price
quantity
size {
id
label
name
}
title
user {
id
}
}
}
`;
// LocalState Query
const { data: cachedItem, error: errorQuery, loading: loadingQuery } = useQuery(
LOCAL_STATE_QUERY,
);
但是由于我已经更改:
cache.writeData({ data });
client_.onResetStore(() => cache.writeData({ data }));
到
cache.modify({ data });
client_.onResetStore(async () => cache.modify({ data }));
localState初始化未按预期工作。我在这里俯瞰什么?
答案 0 :(得分:0)
可以通过以下操作解决此问题:
EvaluateComplete