【发布时间】:2021-06-30 05:09:16
【问题描述】:
谁能帮忙,我发现只有在 Flatlist 中渲染,例如,但我需要没有 Flatlist
import React, { useEffect, useState } from 'react';
从 'react-native' 导入 { ActivityIndicator, FlatList, Text, View };
export default App = () => {
const [isLoading, setLoading] = useState(true);
const [data, setData] = useState([]);
useEffect(() => {
fetch('https://reactnative.dev/movies.json')
.then((response) => response.json())
.then((json) => setData(json.movies))
.catch((error) => console.error(error))
.finally(() => setLoading(false));
}, []);
return (
<View style={{ flex: 1, padding: 24 }}>
{isLoading ? <ActivityIndicator/> : (
<FlatList
data={data}
keyExtractor={({ id }, index) => id}
renderItem={({ item }) => (
<Text>{item.title}, {item.releaseYear}</Text>
)}
/>
)}
</View>
);
};
【问题讨论】: