Siema mam taki problem. Pobieram dane z cache który jest nakładką na AsyncStorage
.
static getDiscounts(categoryAndPage) {
return AsyncStorage.getItem(categoryAndPage);
}
Następnie pobieram sobie te dane i aktualizuję stan poprzez this.set.State()
var discountsPromise = DiscountsCache.getDiscounts(discountCacheKey);
discountsPromise.then(cachedDiscounts => {
if (cachedDiscounts !== null) {
var result = JSON.parse(cachedDiscounts);
this.setState({
discounts: page === 1
? result
: [
...this.state.discounts,
...result
]
})
} else {... tutaj pobieram dane requestem i przypisuje do cache
Na tą zmianę stanu reaguje component w metodzie render
render() {
return (
....
<FlatList
data={this.state.discounts}
renderItem={({item}) => {
var media = item._embedded["wp:featuredmedia"][0]; <-- tutaj dostaję błąd
Błąd
TaskQueue: Error with task : Cannot read property 'wp:featuredmedia' of undefined
Dodam tylko że bez cache, kiedy za każdym razem pobieram dane z API, wszystko działa poprawnie.
EDIT: dostaję jeszcze warning przed wyjątkiem
Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'wp:featuredmedia' of undefined