react-query version 3 Flashcards

1
Q

What kind of state does react-query manage

A

Server state

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

What is client state

A

Information relevant to a browser/front-end application session

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

Examples of client state

A

Chosen theme or language

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

What is server state

A

Data stored remotely in database

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

Example of server state

A

List of blog posts or any other such data

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

Where does react-query fit in

A

It has a cache of server state data, and does a request for new data when required, by using fetch/axios or any other method of fetching server data.

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

What is the source of truth for react-query

A

It’s cache

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

When wil react-query fetch data again?

A

Depends on how it’s been configured declaritively, via the queryclient, or when a key is invalidated imperatively.

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

Example of react-query cache

A

{
key:’blogs’,
data:{}
}

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

Name react-query core features

A

1) loading/error states
2) pagination/infinite scroll
3) Prefetching
4) Mutations and Queries
5) De-duplication of requests
6) Retry on error
7) Callbacks
8) Browser devtools
9) caching of data

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

What are the key react-query items that must be set up?

A

The provider and the query client

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

What is the difference between isLoading and isFetching

A

isLoading - When true, indicates that the query is loading when it has no cached data.

isFetching - When true, indicates that the query is currently fetching, but might have data from an earlier request.

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

What is staleTime

A

How long data can be out of date for before a refetch may be executed.

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

What is default staleTime

A

0ms

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

What is cacheTime

A

The amount of time that the data may be cached by react-query, after the most recent useQuery for this key.

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

What is the default cacheTime?

A

5 minutes

17
Q

What is garbage collection?

A

How the cached data for a given key is deleted after cacheTime is exceeded.

18
Q

How is cached data used by react query?

A

It is backup data that can be rendered while a new fetch is running.

19
Q

Does react-query retry by default

A

yes

20
Q

How many retries does react query do by default

A

3

21
Q

How are the amount of react-query retries configurable

A

Yes, in useQuery() or useMuation() as well as in the queryClient (global)

22
Q

When is the react-query devtools available

A

When process.env.NODE_ENV !== ‘production’ and it’s been imported and instantiated in the app

23
Q

When is data refetched by react-query

A

When data is stale (past staletime for specific query key) and a trigger occurs for that key. Also when no cache for the query key, if cacheTime is past:
1) component remounts
2) window refocusses
3) running of fetch function - returned from useQuery
4) automated refetch at specified interval
5) query invalidation after mutation - makes cache stale for this key

24
Q

How to fetch dynamic data based on id

A

The query key should be an array, the second index being the dynamic data, example id.

25
Q

Why would you use an array as a query key

A

This will create keys for
[‘blog’,1] and [‘blog’,2] independently in the cache for example.