![](/img/trans.png)
[英]React Native. I have just started learning react native and I have a question about return statement
[英]React Native: I have a question with this React
有人可以帮忙吗,我尝试了几乎所有方法,但我没有任何错误或错误:错误是元素类型无效:预期字符串或类/函数但未定义。 检查'App'的渲染方法这里是代码:
import React from 'react';
import { useState } from 'react';
import { Flatlist } from 'react-native';
import {StyleSheet, Text, View} from 'react-native';
export default function App() {
const[todos, setTodos] = useState([
{ text: 'buy coffee' , key: '1' },
{ text: 'learn Redux', key: '2' },
{ text: 'go to gym' , key: '3' }
]);
return (
<View style = {styles.container}>
{/*header */}
<View style = {styles.content}>
{/* to form */}
<View style = {styles.list}>
<Flatlist
data = {todos}
renderItem = {( {item} )=> (
<Text>{item.text} </Text>
)}
/>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff'
},
content: {
padding : 40,
}
});
您对 FlatList 的字母“L”使用了错误的大小写
改变
import { Flatlist } from 'react-native';
至
import { FlatList } from 'react-native';
也改变
<FlatList
data = {todos}
renderItem = {( {item} )=> (
<Text>{item.text} </Text>
)}
/>
Flatlist
=> FlatList
检查数据不是 null 或未定义
renderItem = {( {item} )=> (<Text>{item?.text ?? ''} </Text>)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.