【问题标题】:activate and deactivate textInput激活和停用 textInput
【发布时间】: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


    【解决方案1】:

    因为您没有在按下时调用函数textEdit。像这样更新:

    onPress={() => {
      textEdit();
    }}
    

    或清洁工:

    onPress={textEdit}
    

    【讨论】:

    • 难以置信。感谢您帮助它解决问题。
    猜你喜欢
    • 2014-08-03
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多