【问题标题】:Invariant Violation: View config getter callback for component `input` must be a function (received `undefined`)不变违规:查看组件“input”的配置 getter 回调必须是一个函数(接收到“undefined”)
【发布时间】:2022-12-28 23:22:56
【问题描述】:
    This is my InputItems.js
    
    import React, { useState } from "react";
    import { Text, View, StyleSheet, TextInput, Button } from "react-native-web";
    
    function InputItems(props) {
      const [inputGoal, setinputGoal] = useState("");
      return (
        <View style={style.wholeInputcontainer}>
          <TextInput
            placeholder="Enter the Text"
            style={style.textInput}
            onChangeText={(enteredtext) => {
              setinputGoal(enteredtext);
            }}
            value={inputGoal}
          />
          <Button title="Submit" onPress={props.onpressprop.bind(this,inputGoal)} />
        </View>
      );
    }
    const style = StyleSheet.create({
      wholeInputcontainer: {
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
      },
      textInput: {
        borderBottomColor: "blue",
        borderBottomWidth: 4,
        marginBottom: 10,
        width: 300,
      },
    });
    
    export default InputItems;

and this is my App.js
import React, { useState } from "react";

import { StatusBar } from "expo-status-bar";
import {
  StyleSheet,
  Text,
  View,
  TextInput,
  Button,
  ScrollView,
  FlatList,
} from "react-native";
import Listitems from "./Components/ListItems";
import InputItems from "./Components/InputItems";
// import { Button, TextInput } from 'react-native-web';

export default function App() {
  const [outputGoal, setoutputGoal] = useState([]);
  const Onpress = (InputGoalProp) => {
    setoutputGoal((Currentgoal) => [...Currentgoal, InputGoalProp]);
  };
  return (
    <View style={style.root}>
      <InputItems onpressprop={Onpress} />
      {/* We can use mapping from outputGoal but using FlatList instead of ScrollView is more efficient */}
      <FlatList
        data={outputGoal}
        renderItem={(listitems) => <Listitems anything={listitems.item} />}
      />
      <StatusBar style="auto" />
    </View>
  );
}
const style = StyleSheet.create({
  //StyleSheet is a class of react-native, we can always use inline styleing
  root: {
    marginTop: 100,
  },
});

陷入这个问题。如果可以,请你帮助我。 这是错误...

不变违规:查看组件 input 的配置 getter 回调必须是一个函数(收到 undefined)。确保组件名称以大写字母开头。

此错误位于: 在输入中(由 TextInput 创建) 在 TextInput 中(由 InputItems 创建)

【问题讨论】:

    标签: react-native


    【解决方案1】:

    您在这一行中有错字:

    &lt;Button title="Submit" onPress={props.onpressprop.bind(this,inputGoal)} /&gt;

    this 之后有一个逗号而不是句号。它应该是

    &lt;Button title="Submit" onPress={props.onpressprop.bind(this.inputGoal)} /&gt;

    【讨论】:

      【解决方案2】:

      在InputItems.js 中你仍然有错误的导入(好像你已经在App.js 中更正了):

      改变这个:import { Text, View, StyleSheet, TextInput, Button } from "react-native-web";

      至:import { Text, View, StyleSheet, TextInput, Button } from "react-native";

      【讨论】:

        猜你喜欢
        • 2022-01-22
        • 2021-10-05
        • 1970-01-01
        • 2020-11-11
        • 1970-01-01
        • 2021-06-27
        • 1970-01-01
        • 2016-03-28
        • 2020-08-14
        相关资源
        最近更新 更多