Performance Optimizations with React Query

Just a guy who loves to write code and watch anime.
Search for a command to run...

Just a guy who loves to write code and watch anime.
No comments yet. Be the first to comment.
Qualities that make outstanding builders.

Bipedal vs quadrupedal: how many legs This is about the number of legs the creature walks on. Bipedal. Two legs. Humans, ostriches, T-rex, kangaroos, most fantasy humanoids. Quadrupedal. Four legs. Do

Intro You hear "lerp" and "smoothstep" everywhere in game dev. They sound like math jargon. They're not. Both are small tools that do the same job: smoothly move from one value to another. The problem

What is Kinematics Kinematics is the math field. It's the study of how things move without worrying about forces (which would be dynamics). FK and IK are the two branches: forward kinematics and inver

Intro Textures are usually the biggest cost in a 3D scene. Memory, bandwidth, and load time all get eaten by them. Resizing them is the obvious lever. There's more. This post is about the less obvious

Most APIs return way more data than you need:
// API returns huge user object
const { data: userName } = useQuery({
queryKey: ['user', id],
queryFn: () => fetchUser(id), // Returns 50 fields
select: (user) => user.name // Only subscribe to name changes
})
// Component only re-renders when name changes, not when
// lastLoginAt, preferences, etc. update
// ❌ This kills performance - re-renders on EVERY query state change
const queryResult = useQuery({ queryKey, queryFn })
const allProps = { ...queryResult } // Accesses ALL properties!
// ✅ This only re-renders when data/error change
const { data, error } = useQuery({ queryKey, queryFn })
Without cancellation, you get race conditions and wasted requests:
// User types "react" quickly: r -> re -> rea -> reac -> react
// Without signal: 5 requests, all complete, last one wins
// With signal: 4 requests cancelled, only "react" completes
const { data } = useQuery({
queryKey: ['search', searchTerm],
queryFn: ({ signal }) =>
fetch(`/api/search?q=${searchTerm}`, { signal })
})