【发布时间】:2019-06-01 08:52:50
【问题描述】:
我刚开始使用 react native,我正在从 API 中提取数据。第一个函数成功调用数据,第二个函数需要第一个函数的变量才能成功调用。我正在尝试使第二个 API 调用成功,但它失败了
componentDidMount = async () => {
const communities = await API.getUserCommunityInfo(userId);
console.log(communities)
this.setState({userCommunities: communities, communityMemberId: communities[0].member.id, communityId: communities[0].community.id},
console.log(this.state),
this.getGroups()
)
}
第二个功能
getGroups = async () => {
const groups = await API.getGroups(communityMemberId)
this.setState({userGroups: groups ,showLoader: false})
}
第二个函数在成功调用之前需要第一个函数communityMemberId的状态
【问题讨论】:
标签: reactjs react-native