Skip to content

Instantly share code, notes, and snippets.

@YuCJ
YuCJ / compose-react-refs.jsx
Last active August 30, 2020 15:41
In React, we use `ref` to touch the DOM element directly. When a component takes refs passed by its parent, and it needs to touch the DOM element by itself also, we have to compose the refs into one so we can pass it to the child..
function updateElementInRef(element, ref) {
if (typeof ref === 'function') {
/*
The ref is a callback ref.
https://reactjs.org/docs/refs-and-the-dom.html#callback-refs
*/
ref(element)
} else if (ref) {
/*
The ref is an object expected to be mutated with property `current`.
@YuCJ
YuCJ / TanStack-Query-State-Indicators.md
Created December 2, 2025 08:07
isFetching, isLoading, and isPending

TanStack Query State Indicators: isFetching, isLoading, and isPending

Overview

Understanding the differences between isFetching, isLoading, and isPending is crucial for implementing effective loading states in TanStack Query (React Query) v5.

Definitions

1. isPending

  • true when the query has no cached data yet (awaiting first successful fetch)