【发布时间】: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