
useEffect(() => {
fetchMatches(); // 데이터 가져오기
}, []); // 화면이 처음 마운트될 때
// events.ts
import EventEmitter from 'eventemitter3';
export const matchEventEmitter = new EventEmitter();
// MyPageScreen.tsx
useEffect(() => {
// 이벤트 리스너 등록
const listener = () => {
loadParticipations(); // 데이터 새로고침
};
matchEventEmitter.addListener('matchCreated', listener);
// 클린업
return () => {
matchEventEmitter.removeListener('matchCreated', listener);
};
}, []);
if (response.status === 201 || response.status === 200) {
// Background 상태인 MyPageScreen 새로고침을 위한 이벤트
// (MatchingScreen은 화면 이동 시 자동 새로고침)
matchEventEmitter.emit("matchCreated");
Alert.alert("성공", "매치가 성공적으로 생성되었습니다", [
{ text: "확인", onPress: () => navigation.navigate("MatchingMain") },
]);
}
Focus vs Background
EventEmitter 사용 시기
주의사항