Skip to content

Instantly share code, notes, and snippets.

@eyalcohen4
Last active May 17, 2020 15:06
Show Gist options
  • Save eyalcohen4/c04142ce7a6e0d65552cd3d8db745037 to your computer and use it in GitHub Desktop.
Save eyalcohen4/c04142ce7a6e0d65552cd3d8db745037 to your computer and use it in GitHub Desktop.
React Native Lists
import React from 'react'
function Pokemons() {
}
export default Pokemons
import React from 'react'
import {
View,
Text,
Image,
FlatList
} from 'react-native'
import usePokemons from './use-pokemons'
function Pokemons() {
const pokemons = usePokemons()
return (
<FlatList
data={pokemons}
renderItem={({ item }) => (
<View>
<Text>{item.name}</Text>
<Image source={{ uri: image }} style={{ height: 50, width: 50 }} />
</View>
)}
keyExtractor={(item) => item.name}
/>
)
}
export default Pokemons
import React from 'react'
import {
View,
Text,
Image,
FlatList
} from 'react-native'
import usePokemons from './use-pokemons'
const Pokemon: React.FC<Partial<IPokemon>> = ({
name,
image,
}: Partial<IPokemon>) => {
return (
<View style={pokemonStyles.container}>
<Text style={pokemonStyles.name}>{name}</Text>
<Image source={{ uri: image }} style={pokemonStyles.image} />
</View>
)
}
export default function Pokemons() {
const pokemons = usePokemons()
const renderPokemon = ({ item }: { item: IPokemon }) => {
return <Pokemon name={item.name} image={item.image} />
}
return (
<FlatList
style={styles.list}
data={pokemons}
renderItem={renderPokemon}
keyExtractor={(item) => item.name}
/>
)
}
export default Pokemon
import React from 'react'
import {
View,
Text,
Image,
FlatList
} from 'react-native'
import usePokemons from './use-pokemons'
function Pokemons() {
const pokemons = usePokemons()
const renderPokemon = ({ item }: { item: IPokemon }) => {
return (
<View>
<Text>{item.name}</Text>
<Image source={{ uri: item.image }} style={{ height: 50, width: 50 }} />
</View>
)
}
return (
<FlatList
style={styles.list}
data={pokemons}
renderItem={renderPokemon}
keyExtractor={(item) => item.name}
/>
)
}
export default Pokemons
import React from 'react'
import usePokemons from './use-pokemons'
function Pokemons() {
const pokemons = usePokemons()
}
export default Pokemons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment