Joel and Tanner Linsley chatted about why state management is such a big issue when building UI's, the motivation for creating state management tools, how server State has inherently different problems from UI state and therefore needs to be managed differently. Additionally, Tanner gave a walkthrough of how React Query manages query caching and uses a serializable array or "query key" to do this.
Creating open-source software.
This blog expands more on the motivation of working on open-source software. ⤵️ https://tannerlinsley.com/blog/the-similarities-between-open-source-work-and-running-a-tech-startup
Finding the right tools! An example of this is building React Table.
1. Finite State Machines A finite state machine is a mathematical model of computation that describes the behavior of a system that can be in only one state at any given time.
2. Statecharts Computer scientist David Harel presented this formalism as an extension to state machines in his 1987 paper Statecharts: A Visual Formalism for Complex Systems.
3. Actor Model The actor model is another very old mathematical model of computation that goes well with state machines. It states that everything is an "actor" that can do three things:
There are various categories of state, but every type of state can fall into one of two buckets:
1. Server Cache - State's stored on the server, and we store in the client for quick-access (like user data).
2. UI State - State that's only useful in the UI for controlling the interactive parts of our app (like modal isOpen
state).
Custom Hooks in React is helpful for much more than just managing the local state and one-dimensional side-effects you see in almost every React Hooks example.
They can be used to build sophisticated memoization pipelines and chained effects that automatically manage local and network resources.
But most importantly, they provide a new layer of abstraction to accomplish new and amazing patterns that we couldn't have just over a year ago.
On the surface, this abstraction layer is simply a collection of custom hooks, but when unlocked, it can be the most powerful piece of your application architecture.
Query Keys are serialized deterministically.
This means that no matter the order of keys in objects, all of the following queries would result in the same final query key.
Query keys get passed to the getQueryArgs
function and then it determines the arguments by using the queryKey.
Utils.js
Next, it passes the queryKey
to the useBaseQuery
function to send it off to buildQuery
. useBaseQuery.js
Finally, it's passed to the buildQuery
. queryCache.js
If we take a look at config.js
we'll see that the simplest form of a key is not an array, but an individual string. config.js
When a query needs more information to describe its data uniquely, you can use an array with a string and any number of serializable objects to describe it.
This is where the stableStringify
is used.
This contains a JSON.stringify
function but with a stableStringifyReplacer
that will check if any values are objects. If they are Object, it will sort the keys and remap them back.
"Optimize for deletion when you write your code because if you don't it's easy to end up needing to grind out large rewrites, which contain massive risk."
From Chris Biscardi's Digital Garden: If you can't delete code then you're stuck with it
Implementation Suspense to React Query wasn't hard.
You can set either the global or query level config's suspense option to true.
Its handle by the handleSuspense
function. Github
People are building the same thing, they are not really worried about changes coming to Suspense.