-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
47 lines (40 loc) · 1.59 KB
/
Copy pathApp.js
File metadata and controls
47 lines (40 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { useState, useEffect } from "react"
import { StatusBar } from 'expo-status-bar';
import { ScrollView, Text } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import axios from "axios";
import CryptoList from "./components/CryptoList";
import { appStyles } from "./styles/styles";
import Pagination from "./components/Pagination";
export default function App() {
const [coinsData, setCoinsData] = useState([]);
const [currentPage, setCurrentPage] = useState(1);
const [postsPerPage, setPostsPerPage] = useState(8);
useEffect(() => {
const loadData = async () => {
const response = await axios.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=24&page=1&sparkline=false');
setCoinsData(response.data)
};
loadData();
}, []);
const lastPostIndex = currentPage * postsPerPage;
const firstPostIndex = lastPostIndex - postsPerPage;
const currentPosts = coinsData.slice(firstPostIndex, lastPostIndex)
return (
<ScrollView showsVerticalScrollIndicator={false} style={appStyles.scrollContainer}>
<StatusBar style="light" />
<SafeAreaView style={appStyles.container}>
<Text style={appStyles.headerText}>Crypto Gallery</Text>
{/* CryptoList */}
<CryptoList coinsData={currentPosts} />
{/* Pagination */}
<Pagination
totalPosts={coinsData.length}
postsPerPage={postsPerPage}
setCurrentPage={setCurrentPage}
currentPage={currentPage}
/>
</SafeAreaView>
</ScrollView>
);
}