react-query Flashcards

1
Q

difference between staleTime and cacheTime

A

staleTime tell for how long the refetching be avoided. (default = 0ms)
cacheTime tells, for how long isLoading should be set to false (to give optimistic updates) (default = 5 mins)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

booleans to indicate api call in progress

A

isLoading: when there is no cache and api fetching
isFetching: when there is cache, api is fetching

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

refetchBooleans

A

refetchOnMount: (default is true)
refetchOnWindowFocus : (default is true)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

stock market polling

A

we can poll data at regular intervals using two option keys
refetchInterval, refetchIntervalInBackground

refetchInterval: default value is false, we can set it to ms, and api will be called every set ms

refetchIntervalInBackground: if the window looses focus the polling stops, we can keep the polling on, if by using this key.
default value is false, we can set, it to ms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fetch API on user event

A

2 step process
1. set option enabled:false
2. call refetch on user event.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

callbacks

A

there is onSuccess callback which gets data
there is onError callback which gets error object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

data transformation

A

we can use select option which accepts a selector fn.
selector fn will get data as input argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

if you need list and detail page

A

then you need to use React-Router
useParam to get id from url.
use that id as key in useQuery
this key is available on key = “queryKey” in caller fn.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

need for useQueries hook

A

if the number of useQuery are changing from render to render, it violates rules of hook.
there fore we have useQueries hook, so that we can execute dynamic number of queries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

implementing pagination

A

we can use key = keepPreviousData : true
so that we do not see loading indicator

also don’t forget to use, pageParam, setPageParam

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

infinite query

A
  1. useInfiniteQuery instead of useQuery
  2. hasNextPage
  3. fetchNextPage

instead of data.data, you will get data.pages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how to save a get request after mutation

A

by setting the data returned from mutation into the queryClient.setQueryData

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

optimistic update uses three keys

A

onMutate
onError,
onSettled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly