【发布时间】:2021-05-04 14:26:36
【问题描述】:
我在发送表单数据时遇到的错误警告:无法对未安装的组件执行 React 状态更新。这是一个空操作,但它表明您的应用程序中存在内存泄漏。
export default class AddShipment extends React.Component{
state={
Courier_trackerId: "",
Courier_ShipperName: "",
Courier_PhoneNum: "",
Courier_Address: ""
}
InputTextField=(props)=> {
return (
<View style={props.style}>
<Text style={styles.inputTitle}>{props.title}</Text>
<TextInput
placeholder={props.placeholderText}
secureTextEntry={props.isSecure}
style={styles.input}
onChangeText={
text=>{this.setState({ 'props.var' : text })}
}
/>
<View style={{ borderBottomColor: "#D8D8D8", borderBottomWidth: 1 }} />
</View>
);
}
addNewShipment= async()=>{
firestore().collection("Couriers").add({
TrackerId : this.state.Courier_trackerId,
ShipperName : this.state.Courier_ShipperName,
PhoneNum : this.state.Courier_PhoneNum,
Address : this.state.Courier_Address
})
}
render()
{
return(
<ScrollView style={{backgroundColor:"#FFF", height: "100%", flex: 1, paddingHorizontal: 30}}>
<Text style={[styles.text, { marginTop: 10, fontSize: 22, fontWeight: "500", alignSelf:'center' }]}>Add New Shipment</Text>
<Text style={[styles.text, { color: "#ABB4BD", fontSize: 15, textAlign: "center", marginVertical: 20 }]}>Fill in the details </Text>
<this.InputTextField
style={{marginTop: 25, marginBottom: 8}}
title="Tracking-ID"
var="Courier_trackerId" />
<this.InputTextField
style={{marginTop: 25, marginBottom: 8}}
title="Shipper Name"
var="Courier_ShipperName" />
<this.InputTextField
style={{marginTop: 25, marginBottom: 8}}
title="Phone Number"
var="Courier_PhoneNum" />
<this.InputTextField
style={{marginTop: 25, marginBottom: 8}}
title="Address"
var="Courier_Address" />
<TouchableOpacity style={styles.submitContainer} onPress={this.addNewShipment}>
<Text
style={[
styles.text,
{
color: "#FFF",
fontWeight: "600",
fontSize: 16
}
]}
>
Add Shipment
</Text>
</TouchableOpacity>
</ScrollView>
)
}
}
如果有任何方法可以修改这个现有功能,那将比创建一个全新的功能要好得多,因为我在多个屏幕上使用InputTextField。
【问题讨论】:
标签: firebase react-native google-cloud-firestore