In the ground since Fri Oct 01 2021
Last watered inFri Oct 01 2021
todo Add the most crucial summarized thing to let us recap this topic
….
One Word (main)
stale-while-revalidate caching ????
Every query requires two things:
React query will keep track of all items for the given array. If any of them change, React Query will invalidate the cache , call the given query function again and, store the result in the cache again!
So, we should defintely keep this in mind:
If some state is related to the query function, then it should be places inside the query key’s array!
When active is true, will have two entries on the cache with different key values that have the same data
Even though the result of fetchDynamicUser is the same, the cache will place this result in two different places: inside a key with value of ['array-keys', true, null] inside a key with a value of ['array-keys', null, true]
In an App, we likely face a scenario where multiple pages or components will use the same data. But by changing the array order we may start creating lots of entries on React Query Cache. We don’t need that.
Real Example:
We’re watching three variations: 1) status and id are null. 2)status is active and id is null 3) status is active and id is ‘1’. We have on entry for each variation

With the “order” approach we would have “duplicated” entries.

This prop represents the STATUS OF THE QUERY. It's based on the Promise's status. They're not the same, but pretty similar.
status === "pending" (on Promise language this is "Pending")
It means that query has not yet completed.
status === "success" (on Promise language this is "Fulfilled")
It means that query has completed successfully and data is available.
status === "error" (on Promise language this is "Rejected")
It means that query has completed with an error.
asdsada sdasdsa asdsadsa
This section groups tips and explanations so I can argue about React Query with the most accurate knowledge possible.
If we have more than one component that uses the same query, at least one of them should be responsible for fetching the data. This is the job of the enable property. Example:
screen.tsx
If we have a query that depends on a state that changes on the query function, we may end up with an infinite loop. This is because the query function will be called every time the state changes, and the state changes every time the query function is called. ...