所以我有一大堆数据,我正在从API中检索.我相信问题是我的组件在从promise接收数据之前调用renderMarkers函数.
所以我想知道如何在调用renderMarkers函数之前等待完全解析数据的承诺?
class Map extends Component {
componentDidMount() {
console.log(this.props)
new google.maps.Map(this.refs.map, {
zoom: 12,
center: {
lat: this.props.route.lat,
lng: this.props.route.lng
}
})
}
componentWillMount() {
this.props.fetchWells()
}
renderMarkers() {
return this.props.wells.map((wells) => {
console.log(wells)
})
}
render() {
return (
<div id="map" ref="map">
{this.renderMarkers()}
</div>
)
}
}
function mapStateToProps(state) {
return { wells: state.wells.all };
}
export default connect(mapStateToProps, { fetchWells })(Map);
Run Code Online (Sandbox Code Playgroud)