// CryptoList.
j s
import React, { useState, useEffect } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import axios from 'axios';
const CryptoList = () => {
const [cryptos, setCryptos] = useState([]);
useEffect(() => {
[Link]('[Link]
.then(response => {
setCryptos([Link](0, 4)); // Ambil hanya 4 koin
pertama
})
.catch(error => {
[Link]('Error fetching data: ', error);
});
}, []);
return (
<View style={[Link]}>
{[Link](crypto => (
<View key={[Link]} style={[Link]}>
<Text style={[Link]}>{[Link]}</Text>
<Text style={[Link]}>{[Link]}</Text>
<Text style={[Link]}>{crypto.price_usd}</Text>
</View>
))}
</View>
);
};
const styles = [Link]({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
cryptoContainer: {
marginBottom: 10,
},
name: {},
symbol: {
fontSize: 16,
},
price: {
fontSize: 16,
fontWeight: 'bold',}});
// [Link]
import React from 'react';
import { View, StyleSheet } from 'react-native';
import CryptoList from './CryptoList';const App = () => {
return (<View style={[Link]}><CryptoList />
</View>);}const styles = [Link]({container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',},});
export default App;
Pastikan emulator atau perangkat fisik terhubung dan jalankan aplikasi dengan perintah `npx
react-native run-android` atau `npx react-native run-ios`.