I created a custom component called AchievementBlock which is as follows:
import React from 'react';
import { View, StyleSheet, Image, TouchableOpacity } from 'react-native';
const AchievementBlock = ({ onPress }) => {
return (
<TouchableOpacity onPress={onPress}>
<View style={styles.AchievmentBlockStyle}>
<Image source={require('../../assets/images/Placeholder_Achievement.png')} />
</View>
</TouchableOpacity>
)
}
And used that component as a FlatList in my UserProfileScreen with a the following data:
const tournaments = [
{ title: 'Tournament Title #1', placement: '2nd', desc: 'Description Here', logo: require('../../assets/images/TournamentLogo.png') },
{ title: 'Tournament Title #2', placement: '1st', desc: 'Description Here', logo: require('../../assets/images/TournamentLogo.png') },
{ title: 'Tournament Title #3', placement: '3rd', desc: 'Description Here', logo: require('../../assets/images/TournamentLogo.png') },
]
I then return as follows:
return (
<View style={styles.container}>
<FlatList
data={tournaments}
numColumns={3}
keyExtractor={(tournaments) => {tournaments.title}}
renderItem={({ item }) => {
return (
<AchievementBlock
title={item.title}
placement={item.placement}
onPress={() => navigation.navigate('Achievement')}/>
)
}}
/>
</View>
)
Now I'm stuck on pulling through each rendered FlatList item's data to a new screen when clicking on it.
The on press would be something like this:
onPress={() => navigation.navigate('Achievement', {item.title, item.placement, item.logo, item.desc})}
But that doesn't work and with me still being a beginner with React Native I can't seem to find the solution in pulling each items data through to that screen with the navigation.getParam() function as normal.
What am I doing wrong and how would I achieve this in the best practice?