๋ชฉ๋กuseQuery (2)
๐ค ์์งlog ๐ค
// Main.tsx import { useEffect, useState } from "react"; import styled from "styled-components"; import { useQuery } from "react-query"; import Pagination from "../templates/Pagination"; const Main = () => { // const [post, setPost] = useState([]); const [totalPosts, setTotalPosts] = useState(10); // ํ์ด์ง ๋น ๊ฒ์๋ฌผ ์ const [page, setPage] = useState(1); // ํ์ฌ ํ์ด์ง ๋ฒํธ const offset = (page - 1) * totalP..
๐ก useQuery API์ฐ๋์ ํนํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก Hook์ ๊ธฐ๋ฐ์ผ๋ก ๋ฐ์ดํฐ ๋ก๋ฉ์ ํธํ๊ฒ ๊ตฌํํ๋๋ก ๋์์ค๋๋ค. ๋ฐํ ๊ฐ์ ํ์ฉํ์ฌ ์ฑ๊ณต, ์คํจ ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํฉ๋๋ค. ( isFetching, isLoading, error, state ๋ฑ ) Status isLoading : ํ์ฌ ๋ฐ์ดํฐ ์์ฒญ ์ค isError : ์ค๋ฅ ๋ฐ์ isSuccess : ๋ฐ์ดํฐ ์์ฒญ ์ฑ๊ณต data : ์์ฒญ ์ฑ๊ณตํ ๋ฐ์ดํฐ refetch : ๋ค์ ์์ฒญ์ ์์ํ๋ ํจ์ const Ex = () => { const result = useQuery('posts', postData); const { data, error, isLoading } = result; if (isLoading) return Loading...; if (error)..