【发布时间】:2021-11-07 01:13:44
【问题描述】:
StackOverflow 我正在尝试制作一个按钮来将布尔值从 true 更改为 false,反之亦然,以更改 textInput 中的可编辑值。 这是我到现在为止的距离:
const [change, setChange] = useState(true);
const [text, setText] = useState("");
const textEdit = () => {
change === true ? setChange(false) : setChange(true);
};
由于某种原因,在点击以下 TouchableOpacity 后,它不会改变状态,或者我的代码中一定存在问题,阻止 react 改变下面文本输入中“更改”的状态
<TextInput
style={{ width: "100%", height: 100, backgroundColor: "gray" }}
placeholder={"write something"}
onChangeText={(text) => setText(text)}
editable={change}
>
<Text>adderess</Text>
</TextInput>
<TouchableOpacity
onPress={() => {
textEdit;
}}
>
<Text style={{ color: "blue" }}>Change</Text>
</TouchableOpacity>
【问题讨论】:
标签: reactjs react-native textinput react-native-textinput