首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反应本机功能组件

反应本机功能组件
EN

Stack Overflow用户
提问于 2021-12-07 05:09:38
回答 1查看 79关注 0票数 0

我的代码是:

代码语言:javascript
复制
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`
      );
}

我试图做一个简单的代码,要求输入一些目标,并在控制台中打印文本作为输出。但是我不能在控制台中得到输出。出现了一些长时间的合成错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-07 05:32:55

请通过TextInput guide,将您的onChange道具替换为onChangeText。比如:

代码语言:javascript
复制
<TextInput
    placeholder="Enter Goal"
    style={{ borderBottomWidth: 1, borderColor: "black" }}
    value={entGoal}
    onChangeText={textHandler}
/>

希望这对你有用。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70255217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档