【发布时间】:2017-10-25 21:58:09
【问题描述】:
我正在尝试设置项目的状态,然后将新状态用作传递给我的组件的道具,但它似乎没有及时设置状态
constructor (props) {
super(props)
this.cartFirebase = firebaseApp.database().ref('carts')
this.cartFirebase.child(DeviceInfo.getUniqueID() + '/items').push({
item: this.props.data.name,
qty: 1
}).then((snap) => {
this.state = {
cartKey: snap.key
}
})
}
组件
<AddToCartRow item={this.props.data.sizes} option='size' key={this.state.cartKey}/>
【问题讨论】:
标签: react-native components states prop setstate