-
Notifications
You must be signed in to change notification settings - Fork 0
11회차 과제 - 신혜진 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
11회차 과제 - 신혜진 #19
Conversation
신혜진/src/LanguageProvider.jsx
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useState로 언어 상태를 잘 관리하고 있고, changeLanguage 함수도 간단하고 직관적으로 잘 만드셨어요!
LanguageContext.Provider로 children들을 감싸서, 하위 컴포넌트 어디서든 언어 값을 쉽게 쓸 수 있게 구성한 것도 좋습니다.
구조도 깔끔해서 보기 편하고, 재사용하기에도 딱 좋은것 같아요
신혜진/src/pages/About.jsx
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
language 값을 기준으로 텍스트가 한글/영어로 자연스럽게 바뀌도록 잘 구성하셨어요. 사용자 입장에서 언어 전환이 즉시 적용돼서 훨씬 보기 좋고 편하네요!
profileData[language]처럼 배열도 언어에 따라 다르게 처리한 부분이 특히 인상적이에요. 조건문도 깔끔하게 짜셔서 가독성이 좋은것 같아요 고생하셨습니다!
신경써서 구현한 부분
LanguageContext생성createContext를 통해 Context 객체를 생성하여 이후 컴포넌트에서useContext(LanguageContext)를 통해 접근 가능하도록 구현LanguageProvider구현language상태를 통해 현재 선택된 언어 저장changeLanguage: 버튼 클릭 시 언어를 전환하는 함수Provider를 통해 하위 컴포넌트에 전역으로 language, changeLanguage를 전달App.jsx - Provider 감싸기
LanguageProvider가 App 전체를 감싸도록 구성 -> 모든 페이지에서 언어 상태에 접근할 수 있도록 설정전체적인 언어 전환 기능 구현 방식
1. 삼항 연산자를 사용한 조건부 렌더링
2. 기존 배열 -> 객체 변환
다국어 처리를 위해 기존의 문자열 배열을 다음과 같이 언어별 객체 구조로 변경
그리고 컴포넌트에서는 language 값을 키로 활용하여 아래 코드와 같이 사용하였습니다.
결과 화면
질문
현재 언어 상태가 영어인 상태에서 404 에러 페이지로 이동하면, 해당 페이지에서는 언어가 다시 기본값인 한국어로 초기화되는 문제가 발생하였습니다.
아래 App.jsx 파일에서
<Route path="*" element={<NotFound />} />부분을 중첩 라우팅 안으로 옮겨서 404 페이지에서도 버튼을 통해 언어 전환 기능을 구현하는 것이 최선일지 궁금합니다!