Skip to content

Conversation

jissssu
Copy link

@jissssu jissssu commented Oct 9, 2024

안녕하세요! LG U+ 유레카 프론트엔드 1기 이지수입니다. 미니프로젝트 기간으로 스터디를 쉬다가 🥹😭
오랜만에 타입스크립트를 마주하니 이게 뭐였지...라는 마음에 급하게 다시 찾아보면서 이번 미션을 수행했던 것 같습니다.

이번 주에는 Routing과 상태관리에 대한 미션을 진행하면서, 새로운 페이지를 추가하고 이를 통해 Routing을 구현하는 과정에서 코드 구조의 중요성을 깨달았습니다. 또한 상태관리 라이브러리를 사용해보며, 왜 상태관리 라이브러리를 사용하는지 조금은 알게 된 것 같습니다! 상태관리에 대한 이해도를 더 높이기 위해 더 찾아보고 적용해보는 연습을 해야겠다고 느낀 이번 미션이였습니다 😂


📍알게된 부분

1.상태관리의 필요성
  • 상태관리 라이브러리를 사용하면서 컴포넌트 간의 데이터 흐름을 체계적으로 관리할 수 있음
  • atom과 selector를 통해 상태를 정의하고, 여러 컴포넌트에서 이 상태를 공유하고 업데이트함!

📍Key question

1.SPA / MPA / CSR / SSR 이란 무엇인가요?

  • MPA
    다중 페이지로 이뤄져있어 변경사항이 있을때마다 서버로 페이지를 요청
  • SPA
    단일 페이지로 이루어져 있어 갱신될 부분에 대해서만 데이터 요청
  • CSR
    클라이언트 측에서 렌더링을 하는것
    서버로부터빈 접시(빈 HTML)와 요리 재료(JS)를 받고,요리(렌더링)를 직접 하는 방식
  • SSR
    서버측에서 렌더링 될 페이지를 그려 클라이언트로 내려주는 방식
    서버에서 요리(웹페이지 렌더링)를 완성시킨 후접시에 담아서(완성된 HTML)손님(사용자)에게 제공하는 방식

2.React에서 상태는 어떻게 관리할 수 있나요?

[상태관리라이브러리 외에 잘모르겠어서 서치하였음]

  • 1.useContext API: 전역 상태 관리를 위해 React의 Context API를 사용
  • 2.Custom Hooks:재사용 가능한 상태 관리 로직을 만들기 위해 커스텀 훅을 정의하여 여러 컴포넌트에서 공통의 상태 관리 기능을 구현
  • 3.상태 관리 라이브러리:Redux, MobX, Recoil과 같은 외부 라이브러리를 사용하여 더 복잡한 전역 상태 관리를 수행

3.어떤 상태관리 라이브러리를 사용했고, 그것의 특징은 무엇인가요?

  • Recoil 라이브러리를 사용함
  • 특징: Redux의 복잡성을 줄이고, 상태를 관리하는 데 있어 더 직관적인 방법

📍개선하고싶은 부분

  • 코드 확장성 고려하기
  • 다른 상태 관리 라이브러리에 대해서 사용법 익히기
  • recoil에 대해 더 공부하고 사용하기
  • 채팅 목록 페이지에서 각 채팅방의 마지막 채팅을 표시하는 기능 추가하기

📍결과화면

결과화면

Copy link

@Sieonn Sieonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지수님 이번주 참 정신없는 한 주였죠? 고생 많으셨습니다! 화이팅!! 다음주도 힘내봐요!

"id": 0,
"userName": "jisu",
"userImage": "/src/images/su.png"
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserData와 chatData를 나누셨군요! 저도 고민했던 부분인데 관리하기 편하셨나요?

import chatData from '../public/ChatData.json';
import userData from '../public/UserData.json';


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이번에 좀 덩어리를 크게 잡아서 구현하고자 했는데, 이미 지수님은 실행 중이셨군요! 확실히 이렇게 하니까 확장하기 좋은 것 같습니다.

}
};

// 키보드 이벤트 처리 함수
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

키보드 이벤트를 통해서 입력되는 기능이군요! 저는 늘 못하다가 이번에 처음 구현해봤는데 간단하게 구현할 수 있네요~

@@ -0,0 +1 @@
export const USERID = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭐 때문에 따로 설정해주신 걸까요?

});

// 상수로 분리된 사용자 ID
const MY_ID = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수로 분리해서 사용하는 것을 권장하는 군요!


return (
<HeaderContainer>
<BackButton onClick={handleBackClick}>뒤로</BackButton>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useNavigate사용해서 -1하면 뒤로가기 기능이 됩니다. 브라우저에서 히스토리에 스택을 쌓아놓기 때문에 가능하다고 하더라구요!

Copy link
Member

@Yunil-dev Yunil-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 ~! 이번주차 리뷰어 김윤일입니다!
너무 늦게 왔죠 ? 늦게 온 만큼 꼼꼼하게 봤어요 히히
코드가 저랑 비슷한 부분도 많아서 이해가 빨랐습니다! 저희 다음 주차 미션도 홧팅 해보자구용 !!

import userData from '../assets/data/UserData.json';
import styled from 'styled-components';

const ChatApp = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수를 선언할 때 function을 사용하고 변수 사용 시에 const를 사용하는 것이 가독성 면에도 좋은 거 같습니다!
개인적인 의견이니 한번 참고 해보셔용 😊

<MessagesContainer>
{messages.map((message) => {
const user = users[message.userId];
const isUser = user && user.id === USERID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional Chaining 적용하면 user?.id === USERID로 줄일 수 있습니다 !

font-size: 18px;
color: #333;
display: flex;
margin-left: 250px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

margin-left: 250px;화면 크기에 따라 레이아웃이 깨질 수 있으니 이 부분에서 justify-content:center;로 수정하면 더 유연한 레이아웃이 될 거 같아요 ~

<BackButton></BackButton>
<Title>jisu</Title>
</Header>
<SearchInput type="text" placeholder="이름 검색" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useState를 사용해서 검색 기능을 추가하는 것도 좋을 거 같아요 !

if (userMessages.length === 0) return '메시지가 없습니다';
return userMessages[userMessages.length - 1].text;
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chatData에서 메시지를 필터링하는 방식보단 userId 별로 메시지를 그룹화한 상태로 저장하면 메시지를 필터링할 때 더 효율적으로 접근할 수 있을 거 같아요.
하지만 이번주차는 recoil이 주인공이기 때문에 recoil로 관리한다면 아래 처럼 수정할 수 있을 거 같습니다😊

const users = useRecoilValue(userState);
const chats = useRecoilValue(chatState); 
  
const getLastMessage = (userId: number) => {
    const userMessages = chats.filter(message => message.userId === userId);
    if (userMessages.length === 0) return '메시지가 없습니다'; 
    return userMessages[userMessages.length - 1].text; 
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants