简体   繁体   English

React Native:我对这个 React 有疑问

[英]React Native: I have a question with this React

Can some one help with that please, I tried almost all ways but I can't any mistake or errors: error is Element type is invalid: expected a string or class/function but got undefined.有人可以帮忙吗,我尝试了几乎所有方法,但我没有任何错误或错误:错误是元素类型无效:预期字符串或类/函数但未定义。 Check the render method of 'App' Here is the code:检查'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, 



  }

});

You are using the wrong case for letter 'L' for FlatList您对 FlatList 的字母“L”使用了错误的大小写

Change改变

import { Flatlist } from 'react-native';

To

import { FlatList } from 'react-native';

Also change也改变

   <FlatList
      data = {todos}
      renderItem = {( {item} )=> ( 
          <Text>{item.text} </Text>
         )}
      
      />

Flatlist => FlatList Flatlist => FlatList

check data is not null or undefined检查数据不是 null 或未定义

renderItem = {( {item} )=> (<Text>{item?.text ?? ''} </Text>)}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM