๐Ÿ–ฅFrontEnd/React

tanstack query์˜ isFetching๊ณผ isLoading ์ฐจ์ด, React Query Dev Tools

hellohailie 2024. 12. 29. 22:16
๋ฐ˜์‘ํ˜•

 

isFetching

๋น„๋™๊ธฐ ์ฟผ๋ฆฌ๊ฐ€ ์•„์ง ํ•ด๊ฒฐ๋˜์ง€ ์•Š์•˜๋‹ค.

์•„์ง fetch๊ฐ€ ์™„๋ฃŒ๋˜์ง€ ์•Š์•˜์ง€๋งŒ, axios ํ˜ธ์ถœ์ด๋‚˜ graphGL ํ˜ธ์ถœ ๊ฐ™์€ ๋‹ค๋ฅธ ์ข…๋ฅ˜์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ž‘์—…์ผ ์ˆ˜ ์žˆ๋‹ค. 

 

isLoading

isFetching์˜ ํ•˜์œ„ ์ง‘ํ•ฉ์œผ๋กœ ๋กœ๋”ฉ ์ค‘์ด๋ผ๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค. 

์ฟผ๋ฆฌ ํ•จ์ˆ˜๊ฐ€ ์•„์ง ๋ฏธํ•ด๊ฒฐ์ด์ง€๋งŒ, ์บ์‹œ๋œ ๋ฐ์ดํ„ฐ๋„ ์—†๋‹ค. 

์ด ์ฟผ๋ฆฌ๋ฅผ ์ „์— ์‹คํ–‰ํ•œ ์ ์ด ์—†์–ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘์ด๊ณ  ์บ์‹œ๋œ ๋ฐ์ดํ„ฐ๋„ ์—†์–ด์„œ ๋ณด์—ฌ์ค„ ์ˆ˜ ์—†๋‹ค. 

 

=> ํŽ˜์ด์ง€๋„ค์ด์…˜ ์ธก๋ฉด์—์„œ ์บ์‹œ๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”

 

 

React Query Dev Tools

=> ๋ชจ๋“  ์ฟผ๋ฆฌ์˜ ์ƒํƒœ, ํ™œ์„ฑ, ๋น„ํ™œ์„ฑ, stale(์˜ค๋ž˜๋จ) ๋“ฑ์„ ์•Œ๋ ค์ค€๋‹ค. 

=> ๋งˆ์ง€๋ง‰ ์—…๋ฐ์ดํŠธ ์‹œ๊ฐ„๋„ ์•Œ๋ ค์ค€๋‹ค. 

 

=> ๋ฐ์ดํ„ฐ ํƒ์ƒ‰๊ธฐ๋„ ์žˆ์–ด์„œ ์ฟผ๋ฆฌ๋กœ ๋ฐ›์€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. 

=> ์ฟผ๋ฆฌ ํƒ์ƒ‰๊ธฐ๋Š” ์ฟผ๋ฆฌ ์ž์ฒด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. 

 

@tanstak/react-query-devtools ์—์„œ ์˜จ๋‹ค. 

 

QueryClientProvider ๋‚ด์—์„œ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. 

import { Posts } from "./Posts";
import "./App.css";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";

const queryClient = new QueryClient();

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <div className='App'>
        <h1>Blog &apos;em Ipsum</h1>
        <Posts />
      </div>
      <ReactQueryDevtools />
    </QueryClientProvider>
  );
}

export default App;
๋ฐ˜์‘ํ˜•