问题
I write component witch some caching functionallity. It is based on async storage.
static getDiscounts(categoryAndPage) {
return AsyncStorage.getItem(categoryAndPage);
}
so It returning a promise. So inside my funtion I call then
on this promise.
makeRemoteRequest() {
this.setState({loading: true});
const page = this.state.page;
const catId = this.props.navigation.state.params.categoryId;
var discountCacheKey = `${catId}_${page}`;
var discountsPromise = DiscountsCache.getDiscounts(discountCacheKey);
discountsPromise.then(cachedDiscounts => {
if (cachedDiscounts !== null) {
this.setState({
discounts: page === 1
? cachedDiscounts
: [
...this.state.discounts,
...cachedDiscounts
],
loading: false
})
}
In render function I have FlatList
component which is based on this.state.discounts
<FlatList
data={this.state.discounts}
renderItem={({item}) => {
var media = item._embedded["wp:featuredmedia"][0]; <--- here I get error.
...
Previously without caching and promises everything was fine.
Error:
TaskQueue: Error with task : Cannot read property 'wp:featuredmedia' of undefined
来源:https://stackoverflow.com/questions/45066947/task-queue-error-with-task-cannot-read-property-of-undefined