Overview
TheCryptoList component is responsible for displaying a scrollable list of cryptocurrencies. It uses the useCryptoData hook to fetch cryptocurrency data and manages three distinct states:
- Loading: Shows a spinner while data is being fetched
- Error: Displays an error message if data fetching fails
- Success: Renders the list of cryptocurrencies using
CryptoCardcomponents
useCryptoData hook.
Props
This component does not accept any props. All data management is handled internally through theuseCryptoData hook.
Usage Example
With Layout Container
Component States
- Loading State
- Error State
- Success State
Displayed while cryptocurrency data is being fetched from the API.Visual elements:
- Large green activity indicator (
#00e676) - “Cargando criptomonedas…” text message
- Centered vertically and horizontally
- 100px top padding
Data Hook Integration
The component uses theuseCryptoData hook to manage data fetching:
data: Array ofCryptoApiResponseobjectsloading: Boolean indicating fetch in progresserror: Error object if fetch failed, null otherwise
Styling Details
List Container
- Horizontal padding: 16px on left and right for margin from screen edges
- Top padding: 10px spacing from header
- Bottom padding: 100px to ensure last items are scrollable above any bottom navigation
Center Container (Loading/Error)
Text Styles
Performance Considerations
The component uses
FlatList instead of ScrollView for optimal performance with large datasets. FlatList only renders visible items and recycles components as you scroll.Key Extraction
ThekeyExtractor function uses the cryptocurrency’s ID to provide stable keys:
Component Flow
Related Components
- CryptoCard: Individual card component rendered for each cryptocurrency
- HomeHeader: Header component typically placed above CryptoList
- SearchBar: Search component for filtering the cryptocurrency list
Source Code Location
~/workspace/source/src/components/CryptoList.tsx:20