import React, { useEffect } from 'react'; import { View, Text, FlatList, TouchableOpacity, StyleSheet } from 'react-native'; import { useDispatch, useSelector } from 'react-redux'; import { setEvents, toggleFavorite } from '../store/eventsSlice'; import { RootState } from '../store/store'; export default function EventsScreen({ navigation }: any) { const dispatch = useDispatch(); const { events, favorites } = useSelector((state: RootState) => state.events); useEffect(() => { fetch('https://jsonplaceholder.typicode.com/posts') .then(res => res.json()) .then(data => { const mappedEvents = data.slice(0, 20).map((item: any) => ({ id: item.id.toString(), name: item.title, description: item.body, date: new Date().toISOString(), })); dispatch(setEvents(mappedEvents)); }); }, []); return ( item.id} renderItem={({ item }) => ( navigation.navigate('Details', { event: item })} > {item.name} dispatch(toggleFavorite(item.id))} style={styles.favBtn} > {favorites.includes(item.id) ? '❤️' : '🤍'} )} /> ); } const styles = StyleSheet.create({ container: { flex: 1, padding: 16, backgroundColor: '#000000' }, item: { padding: 16, borderBottomWidth: 1, borderBottomColor: '#333333', flexDirection: 'row', justifyContent: 'space-between' }, title: { fontSize: 16, flex: 1, color: '#ffffff' }, favBtn: { padding: 8 }, });