【发布时间】:2021-01-17 04:26:30
【问题描述】:
我正在尝试使用 javscript 和 expo 添加简单的 textInput 一切都运行良好,除非尝试更改 text 的值给我一个错误
我确实尝试了很多东西,但没有任何效果
const AccountsAddScreen = props => {
const [inputList, setInputList] = useState([{accountName : ""}]);
const handleInputChange = (e, index) => {
const list = [...inputList]
const {accountName, value } = e.target
list[index][accountName] = value;
setInputList(list);
};
const handleRemoveClick = index => {
const list = [...inputList];
list.splice(index, 1);
setInputList(list);
}
const handleAddClick = () => {
setInputList([...inputList, {accountName : ''}]);
}
console.log(single)
return (
<View style = {styles.container}>
<Text>
We are Testing
</Text>
<View>
{
inputList.map((x, i) => {
return (
<View key = {i}>
<TextInput
placeholder = 'Add Account Name'
style = {styles.input}
value = {x.accountName}
onChangeText = {e => handleInputChange(e, i)}
/>
{
inputList.length !== 1 && <Button title = 'Remove' onPress = {()=> { handleRemoveClick(i)}}/>
}
{
inputList.length - 1 === i && <Button title = 'Add' onPress = {handleAddClick} />
}
</View>
);
})
}
</View>
</View>
);
}
const styles = StyleSheet.create({
input : {
borderColor : 'black',
borderWidth : 1
}
});
export default AccountsAddScreen;
我得到的错误是
TypeError: undefined is not an object (evalating '_e$target.accountName')
【问题讨论】:
标签: javascript react-native expo react-native-android textinput