🐳React | React Query μ „μš© Devtools

μ›μ˜Β·2023λ…„ 8μ›” 16일
1

μƒˆλ‘œμš΄ μ§€μ‹πŸ’‘

λͺ©λ‘ 보기
13/15
post-thumbnail

πŸ”ŽReact Query Devtools

  • κ³΅μ‹λ¬Έμ„œ
  • React Query μ’€ 더 μ‰½κ²Œ λ‹€λ£° 수 있게 λ„μ™€μ£ΌλŠ” μ „μš© devtools

πŸ’‘ν™˜κ²½ μ„ΈνŒ…ν•˜κΈ°

  1. μ„€μΉ˜
// npm μ‚¬μš©ν•˜λŠ” 경우
npm i @tanstack/react-query-devtools
// yarn μ‚¬μš©ν•˜λŠ” 경우
yarn add @tanstack/react-query-devtools
  1. μƒμœ„ νŒŒμΌμ—μ„œ import (일반적으둜 App.js)
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
  1. μ‹€ν–‰ν•˜κΈ°
  • importν•œ 파일 κ°€μž₯ ν•˜μœ„μ— ν•΄λ‹Ή μ½”λ“œ μΆ”κ°€
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      {/* κ°€μž₯ ν•˜μœ„μ— ν•΄λ‹Ή μ½”λ“œ μΆ”κ°€ */}
      <ReactQueryDevtools initialIsOpen={true} />
    </QueryClientProvider>
  )
}

πŸ’‘μ‚¬μš©ν•˜κΈ°

A : ν˜„μž¬ μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜μ—μ„œ μΊμ‹œλœ 데이터 key
B : ν˜„μž¬ λͺ‡κ°œμ˜ μ»΄ν¬λ„ŒνŠΈμ—μ„œ 이 μš”μ†Œ κ°„μ§ν•˜κ³  μžˆλŠ”μ§€ λ‚˜νƒ€λƒ„
C : ν˜„μž¬ 이 μš”μ†Œμ˜ μƒνƒœ λ‚˜νƒ€λƒ„

  • fresh : μ‹ μ„ ν•œ μƒνƒœ(μƒˆλ‘œμš΄ query 생성돼도 λ„€νŠΈμ›Œν¬ 톡신 X)
  • fetching : λ„€νŠΈμ›Œν¬ 톡신쀑인 μƒνƒœ
  • paused : 쿼리가 μΌμ‹œμ μœΌλ‘œ 멈좘 μƒνƒœ
  • stale : 였래된 μƒνƒœ(μƒˆλ‘œμš΄ query μƒμ„±λ˜λ©΄ λ„€νŠΈμ›Œν¬ 톡신 λ°œμƒ)

Observers : κ΄€μ°°ν•˜κ³  μžˆλŠ” μ»΄ν¬λ„ŒνŠΈ 개수
Last Upadated : λ§ˆμ§€λ§‰μœΌλ‘œ μ—…λ°μ΄νŠΈ 된 μ‹œκ°„
Actions : μˆ˜λ™μ μœΌλ‘œ λˆŒλŸ¬μ„œ ν•΄λ‹Ή 쿼리에 μ μš©μ‹œν‚΄

  • Refetch : 쿼리λ₯Ό μƒˆλ‘œκ³ μΉ¨ν•˜μ—¬ μƒˆλ‘œμš΄ 데이터 κ°€μ Έμ˜΄(μž¬μš”μ²­)
  • Invalidate : μΊμ‹œλœ 데이터 λ¬΄νš¨ν™”, λ‹€μŒμ— ν•΄λ‹Ή 쿼리 λ‹€μ‹œ 싀행될 λ•Œ μƒˆλ‘œμš΄ 데이터 κ°€μ Έμ˜΄
  • Reset : μƒˆλ‘œκ³ μΉ¨ν•˜μ§€ μ•Šκ³  μΊμ‹œλœ 데이터 μˆ˜λ™μœΌλ‘œ μ΄ˆκΈ°ν™”
  • Remove : μΊμ‹œλœ 데이터 제거
  • Trigger loading : λ‘œλ”©μƒνƒœ 유발
  • Trigger error : μ—λŸ¬μƒνƒœ 유발

Data Explorer : λ„€νŠΈμ›Œν¬ ν†΅μ‹ μœΌλ‘œ λ°›μ•„μ˜¨ 데이터 정보
Query Explorer : μ˜΅μ…˜ 사항듀(cacheTime, queryKey ...)

profile
ν™”μ΄νŒ…~~^ㅁ^/

0개의 λŒ“κΈ€