React Query Flashcards

1
Q

What is React Query?
A) Library
B) Framework
C) Programming language
D) Operating system

A

React Query is a “Library”

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

What is React Query primarily used for?

A

Managing server state in React applications.

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

True or False: React Query automatically caches data fetched from the server.

A

True.

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

Fill in the blank: React Query allows you to perform _______ and _______ operations on remote data.

A

fetching, mutating.

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

What hook is commonly used to fetch data with React Query?

A

useQuery.

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

What is the purpose of the ‘staleTime’ option in React Query?

A

To define how long data is considered fresh before it is refetched.

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

Which method would you use to update data on the server in React Query?

A

useMutation.

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

What is the default behavior of React Query regarding refetching data on window focus?

A

It refetches data by default when the window is refocused.

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

Multiple Choice: Which of the following is NOT a feature of React Query?
A) Caching
B) Synchronization
C) Form validation
D) Background refetching

A

C) Form validation.

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

True or False: React Query can be used with any type of data source, not just REST APIs.

A

True.

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

What is the primary benefit of using React Query over traditional state management for server state?

A

It simplifies data fetching, caching, and synchronization, reducing boilerplate code.

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

How does React Query differ from Redux, Zustand or the Context API (React Context)?

A

React Query handles “Server state”, while Redux, Zustand, Context API, etc handle “client state”

Whenever we’re dealing with React Query, we’re dealing with “Server changes”. So, the data that comes from a Server will change.

While Redux, Zustand, Context API, etc, handle the UI changes.

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

True or False: React Query automatically caches data.

A

True.

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

Fill in the blank: React Query helps reduce the need for _____ in data fetching.

A

useEffect.

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

Which of the following is a benefit of using React Query over useEffect?
A) Simplified data fetching
B) Manual state management
C) Increased boilerplate code

A

A) Simplified data fetching.

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

What feature does React Query provide that helps with data synchronization?

A

Automatic refetching of data.

17
Q

In what scenario would you prefer React Query over useEffect?

A

When managing complex server state and caching requirements.

18
Q

True or False: React Query requires more boilerplate code than useEffect.

19
Q

What is one of the main advantages of React Query’s caching mechanism?

A

It reduces the number of network requests.

20
Q

Short answer: Name a common use case for React Query.

A

Fetching data from an API.

21
Q

How does React Query handle background data updates?

A

It automatically refetches data in the background.

22
Q

What is the purpose of the ‘staleTime’ option in React Query?

A

To define how long data is considered fresh before it is refetched.

23
Q

True or False: React Query can handle pagination and infinite scrolling easily.

24
Q

What does the useQuery hook return in React Query?

A

An object containing the current state of the request, including data and loading status.

25
Q

Fill in the blank: React Query provides built-in _____ for error handling.

A

error management.

26
Q

Why is it beneficial to use React Query’s ‘onSuccess’ and ‘onError’ callbacks?

A

To perform side effects based on the result of the query.

27
Q

What’s the purpose of the queryKey in React Query?

A

The queryKey is a “unique identifyer” for the data we cach in our query call.