Redux & Redux Toolkit Course
Redux & Redux Toolkit
/
Beginner

Queries

Definition

Endpoints defined in RTK Query that are used strictly for READ operations (fetching data from the server). Typically maps to a `GET` request.

Explain Like I'm New

A Query is when you ask the server for information without changing anything. 'Give me the user profile.' RTK Query aggressively caches Queries to save bandwidth.

Real World Example

Fetching a list of blog posts to display on the homepage. You define a `getPosts: builder.query({...})` endpoint.

Common Use Cases

  • •Fetching data
  • •GET requests

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What type of HTTP request is used by default for a Query?

intermediate

  • What happens if a component unmounts while a Query is still fetching?

Flash Cards

Question

HTTP request?

Click to reveal answer
Answer

A `GET` request.

Question

Unmounts while fetching?

Click to reveal answer
Answer

RTK Query will automatically abort the fetch request to save bandwidth and prevent memory leaks.