Skip to content

Commit

Permalink
chore(home): 홈 화면과 커넥트 화면에서 유저 리스트 유지
Browse files Browse the repository at this point in the history
개요

- 홈과 커넥트 화면에서 유저의 목록이 새로 매번 바뀐다.

수정사항

- 기존 useFocusEffect와 useCallback의 조합은 그대로 놔두고(notification
fetch와 같은 기능 때문에) useRef를 활용한 플래깅 기능을 추가해서 앱을 껐다
키는 경우에만 새로 fetch 하도록 추가한다.
  • Loading branch information
seungholee-dev committed Nov 24, 2024
1 parent 54c3171 commit d6c7e91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/pages/connect/ConnectPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback } from "react";
import React, { useState, useCallback, useRef } from "react";
import {
View,
Text,
Expand Down Expand Up @@ -35,10 +35,11 @@ const ConnectPage = () => {
const { t } = useTranslation();
const navigation = useNavigation();

const isInitialMount = useRef(true);
const [profileDataList, setProfileDataList] = useState([]);
const RANDOM_MEMBER_COUNT = 10;

const cardProfiles = async () => {
const fetchCardProfiles = async () => {
try {
const response = await getRandomMembersByCount(RANDOM_MEMBER_COUNT);
const updatedData = formatProfileData(response.data);
Expand All @@ -57,7 +58,10 @@ const ConnectPage = () => {

useFocusEffect(
useCallback(() => {
cardProfiles();
if (isInitialMount.current) {
fetchCardProfiles();
isInitialMount.current = false;
}
}, []),
);

Expand Down Expand Up @@ -119,7 +123,7 @@ const ConnectPage = () => {
const [isReset, setIsReset] = useState(false);

const handleReset = () => {
cardProfiles();
fetchCardProfiles();
setTotalSelection(null);
setIsReset(!isReset);
};
Expand Down
10 changes: 7 additions & 3 deletions src/pages/home/HomePage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback } from "react";
import React, { useState, useCallback, useRef } from "react";
import { LinearGradient } from "expo-linear-gradient";
import {
View,
Expand Down Expand Up @@ -39,12 +39,13 @@ const HomePage = () => {
const { t } = useTranslation();
const navigation = useNavigation();

const isInitialMount = useRef(true);
const [profileDataList, setProfileDataList] = useState([]);
const [notificationNumber, setNotificationNumber] = useState(0);

const RANDOM_MEMBER_COUNT = 10;

const homeProfile = async () => {
const fetchProfileQueue = async () => {
try {
const response = await getRandomMembersByCount(RANDOM_MEMBER_COUNT);
const updatedData = formatProfileData(response.data);
Expand Down Expand Up @@ -87,8 +88,11 @@ const HomePage = () => {

useFocusEffect(
useCallback(() => {
if (isInitialMount.current) {
fetchProfileQueue();
isInitialMount.current = false;
}
getNotificationNumber();
homeProfile();
}, []),
);

Expand Down

0 comments on commit d6c7e91

Please sign in to comment.