Created
October 7, 2021 20:28
-
-
Save xiongemi/c78c719e70aa4948b98e68033d7fe4a3 to your computer and use it in GitHub Desktop.
daily-horoscope-app zodiac-sign-list with useNavigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
AdhZodiacSignItem, | |
AdhZodiacSignList, | |
} from '@aztro-daily-horoscope/models'; | |
import { useNavigation } from '@react-navigation/native'; | |
import React from 'react'; | |
import { FlatList } from 'react-native'; | |
import { ListItem } from 'react-native-elements'; | |
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; | |
import { connect } from 'react-redux'; | |
import { | |
ZodiacSignListProps, | |
mapDispatchToProps, | |
} from './zodiac-sign-list.props'; | |
export function ZodiacSignList({ setUserZodiacSignItem }: ZodiacSignListProps) { | |
const navigation = useNavigation(); | |
const keyExtractor = (item: AdhZodiacSignItem) => item.zodiacSign; | |
const zodiacListItemPress = (item: AdhZodiacSignItem) => { | |
navigation.navigate('Horoscope Card'); | |
setUserZodiacSignItem(item); | |
}; | |
return ( | |
<FlatList | |
keyExtractor={keyExtractor} | |
data={AdhZodiacSignList} | |
renderItem={({ item }) => ( | |
<ListItem bottomDivider onPress={() => zodiacListItemPress(item)}> | |
<Icon name={item.icon} /> | |
<ListItem.Content> | |
<ListItem.Title>{item.zodiacSign}</ListItem.Title> | |
</ListItem.Content> | |
<ListItem.Chevron /> | |
</ListItem> | |
)} | |
/> | |
); | |
} | |
export const ZodiacSignListContainer = connect( | |
null, | |
mapDispatchToProps | |
)(ZodiacSignList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment