簡體   English   中英

React Native:我對這個 React 有疑問

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM