} /> // 컴포넌트에서 사용 import { useParams } from 'react-router-dom'; function UserProfile() { const { userId } = useParams(); return
User ID: {userId}
; } ``` ### 주요 사용 사례 - 블로그 포스트: `/post/:postId` - 상품 상세: `/product/:productId` - 다중 파라미터: `/category/:categoryId/product/:productId` - 사용자 대시보드: `/dashboard/:userId/settings` ### 참고 자료 - [React Router 공식 문서](https://reactrouter.com/start/library/routing) - [FreeCodeCamp - Dynamic Segments](https://www.freecodecamp.org/news/use-dynamic-segments-in-react-router/) --- ## 2. 네트워크 속도가 느린 환경에서의 UX 개선 ### UI/UX 디자인 전략 **스켈레톤 스크린** - 빈 화면 대신 콘텐츠 윤곽 표시 - 체감 로딩 속도 개선 **점진적 로딩** - 중요한 콘텐츠 우선 표시 - 부가 콘텐츠는 지연 로드 **명확한 피드백** - 로딩 상태 표시 - 진행률 바 또는 메시지 제공 **오프라인 지원** - Service Worker 활용 - 캐시된 데이터로 기본 기능 제공 ### 기술적 최적화 방법 "> } /> // 컴포넌트에서 사용 import { useParams } from 'react-router-dom'; function UserProfile() { const { userId } = useParams(); return
User ID: {userId}
; } ``` ### 주요 사용 사례 - 블로그 포스트: `/post/:postId` - 상품 상세: `/product/:productId` - 다중 파라미터: `/category/:categoryId/product/:productId` - 사용자 대시보드: `/dashboard/:userId/settings` ### 참고 자료 - [React Router 공식 문서](https://reactrouter.com/start/library/routing) - [FreeCodeCamp - Dynamic Segments](https://www.freecodecamp.org/news/use-dynamic-segments-in-react-router/) --- ## 2. 네트워크 속도가 느린 환경에서의 UX 개선 ### UI/UX 디자인 전략 **스켈레톤 스크린** - 빈 화면 대신 콘텐츠 윤곽 표시 - 체감 로딩 속도 개선 **점진적 로딩** - 중요한 콘텐츠 우선 표시 - 부가 콘텐츠는 지연 로드 **명확한 피드백** - 로딩 상태 표시 - 진행률 바 또는 메시지 제공 **오프라인 지원** - Service Worker 활용 - 캐시된 데이터로 기본 기능 제공 ### 기술적 최적화 방법 "> } /> // 컴포넌트에서 사용 import { useParams } from 'react-router-dom'; function UserProfile() { const { userId } = useParams(); return
User ID: {userId}
; } ``` ### 주요 사용 사례 - 블로그 포스트: `/post/:postId` - 상품 상세: `/product/:productId` - 다중 파라미터: `/category/:categoryId/product/:productId` - 사용자 대시보드: `/dashboard/:userId/settings` ### 참고 자료 - [React Router 공식 문서](https://reactrouter.com/start/library/routing) - [FreeCodeCamp - Dynamic Segments](https://www.freecodecamp.org/news/use-dynamic-segments-in-react-router/) --- ## 2. 네트워크 속도가 느린 환경에서의 UX 개선 ### UI/UX 디자인 전략 **스켈레톤 스크린** - 빈 화면 대신 콘텐츠 윤곽 표시 - 체감 로딩 속도 개선 **점진적 로딩** - 중요한 콘텐츠 우선 표시 - 부가 콘텐츠는 지연 로드 **명확한 피드백** - 로딩 상태 표시 - 진행률 바 또는 메시지 제공 **오프라인 지원** - Service Worker 활용 - 캐시된 데이터로 기본 기능 제공 ### 기술적 최적화 방법 ">
# React 기술 질문 답변

## 1. React Router의 동적 라우팅(Dynamic Routing)

### 정의
- URL의 특정 부분을 변수처럼 사용하여 하나의 라우트로 여러 페이지 처리
- `:` 기호로 동적 세그먼트 정의

### 기본 사용법
```jsx
// 라우트 정의
<Route path="/user/:userId" element={<UserProfile />} />

// 컴포넌트에서 사용
import { useParams } from 'react-router-dom';

function UserProfile() {
  const { userId } = useParams();
  return <div>User ID: {userId}</div>;
}

주요 사용 사례

참고 자료


2. 네트워크 속도가 느린 환경에서의 UX 개선

UI/UX 디자인 전략

스켈레톤 스크린

점진적 로딩

명확한 피드백

오프라인 지원

기술적 최적화 방법

이미지 최적화

<img 
  src="image.webp" 
  loading="lazy"
  srcSet="small.webp 400w, large.webp 800w"
/>

Code Splitting

const Heavy = lazy(() => import('./Heavy'));

<Suspense fallback={<Skeleton />}>
  <Heavy />
</Suspense>

데이터 캐싱

const { data } = useQuery({
  queryKey: ['user', userId],
  queryFn: fetchUser,
  staleTime: 5 * 60 * 1000
});

기타 최적화

참고 자료


3. React 상태 관리 비교

지역 상태 관리

useState

const [count, setCount] = useState(0);

useReducer

const [state, dispatch] = useReducer(reducer, initialState);

Context API

특징

장점

단점

적합 케이스

전역 상태 라이브러리

Zustand (가볍고 간단)

const useStore = create((set) => ({
  count: 0,
  increment: () => set((state) => ({ count: state.count + 1 }))
}));

// Provider 없이 사용
const { count, increment } = useStore();

Redux Toolkit (대규모 앱)

const slice = createSlice({
  name: 'counter',
  initialState: { value: 0 },
  reducers: { increment: state => { state.value += 1 } }
});

선택 가이드

상황 추천 도구
단일 컴포넌트 간단한 상태 useState
복잡한 로컬 상태 로직 useReducer
prop drilling 해결 (소규모) Context API
중간 규모 앱 Zustand
대규모, 복잡한 비즈니스 로직 Redux Toolkit
서버 상태 React Query/SWR

실전 팁

참고 자료