我的代码是:
import { StatusBar } from "expo-status-bar";
import React, { useState } from "react";
import { StyleSheet, Text, View, Button, TextInput } from "react-native";
export default function App() {
const [entGoal, setEntGoal] = useState("");
const textHandler = (entText) => {
setEntGoal(entText);
};
const addHandler = () => {
console.log(entGoal);
};
return (
<View style={{ margin: 12, padding: 50 }}>
<View>
<Text>Goals List!</Text>
<TextInput
placeholder="Enter Goal"
style={{ borderBottomWidth: 1, borderColor: "black" }}
value={entGoal}
onChange={textHandler}
/>
<Button title="Add (+)" onPress={addHandler} />
</View>
</View>`enter code here`
);
}我试图做一个简单的代码,要求输入一些目标,并在控制台中打印文本作为输出。但是我不能在控制台中得到输出。出现了一些长时间的合成错误。
发布于 2021-12-07 05:32:55
请通过TextInput guide,将您的onChange道具替换为onChangeText。比如:
<TextInput
placeholder="Enter Goal"
style={{ borderBottomWidth: 1, borderColor: "black" }}
value={entGoal}
onChangeText={textHandler}
/>希望这对你有用。
https://stackoverflow.com/questions/70255217
复制相似问题