0
我有一個SectionList,其中包含大量從Firebase存儲中獲取的圖像。當向下滾動時,迅速建立了很多警告。在ScrollView/FlatList/SectionList中反應本機異步(firebase)圖像獲取
的WebImage組件看起來是這樣的:
import React, { Component } from 'react'
import { View, Image } from 'react-native'
import firebase from 'firebase'
class WebImage extends Component {
state = {
imgsrc: '',
mounted: false,
}
componentDidMount() {
this.setState({ mounted: true })
firebase
.storage()
.ref()
.child(this.props.source)
.getDownloadURL()
.then(url => {
if (this.state.mounted) {
this.setState({ imgsrc: url })
}
})
}
componentWillUnmount() {
this.setState({ mounted: false })
}
render() {
...
}
}
export default WebImage
正如你可以看到我試圖使它意識到安裝狀態,但預期它沒有工作..