W komponecie chce odczytać id
, ale dostaję undefined
. Jak odczytać
<View style={styles.container}>
<FlatList
numColumns={4}
data={hours}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (<HoursComponent {... item} />)} />
const HoursComponent = ({id, time}) => {
const [bgColor, setBgColor] = useState('');
const [markedHour, setMarkedHour] = useState('');
console.log(typeof id);
const onPress = () => {
if(bgColor == '') {
console.log("Time " + time + " ID " + id)
setBgColor(Colors.sandy)
}else{
setBgColor('#00000000');
}
}
const TimewithoutLast3 = time.slice(0, -3);
return (
<TouchableOpacity style={{...styles.rootContainer, backgroundColor: bgColor}}>
<Text style={styles.buttonText} onPress={onPress}>{TimewithoutLast3}</Text>
</TouchableOpacity>
);
}
W backend godzina jest zdefiniowana tak
Hours first = new Hours(1l, LocalTime.of(9, 00));
({}).toString()
w JS daje właśnie stringa "[object Object]"