Task Queue error with task : Cannot read property of undefined

血红的双手。 提交于 2021-01-28 07:22:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!