Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 리액트
- 클래스 추가하기 #특정 url 클래스 추가 #사이트 접속시 클래스 추가 #오공완 #javascript
- 오공완
- React
- map()에는 key값이 필요
- 오공완 #리액트 공부 #React
- 리스트랜더링
Archives
- Today
- Total
new_bird-hyun
React Query - 복잡한 서버 상태 핸들링 본문
npm install @tanstack/react-query
import { useQuery, QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
function Posts() {
const { data, isLoading, error } = useQuery(['posts'], () =>
fetch('/api/posts').then(res => res.json())
);
if (isLoading) return <p>불러오는 중...</p>;
if (error) return <p>에러!</p>;
return (
<ul>
{data.map((post: any) => (
<li key={post.id}>{post.title}</li>
))}
</ul>
);
}
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<Posts />
</QueryClientProvider>
);
}
'코딩 공부' 카테고리의 다른 글
React - framer-motion으로 페이지 전환 애니메이션 (0) | 2025.04.13 |
---|---|
JavaScript - 배열 요소를 랜덤 섞기 (Fisher-Yates Shuffle) (2) | 2025.04.13 |
React - SWR로 서버 데이터 fetch + 캐싱 (0) | 2025.04.09 |
JavaScript - 화면 사이즈 감지하는 유틸 만들기 (0) | 2025.04.09 |
ReactDOM.createPortal로 모달 구현하기 (0) | 2025.04.06 |