Menu

1 / 4

Why Your Nextjs UI Flickers: TanStack Query vs useEffect

DEV Community·nishchal singh·6 months ago
#iTbkg64n
#rendering#nextjs#performance#react#strategy
Reading 0:00
15s threshold

A page can load quickly and still feel unstable.

That usually happens when the initial render strategy is fine, but client-side data updates are handled poorly.

In this article, we’ll compare two common approaches:

A basic useEffect fetch

A production-ready pattern using TanStack Query

Both fetch the same API under the same network conditions.

One flickers.

The other stays smooth.

The Experiment

I built a small Next.js Rendering Lab to visualize:

SSR

CSR

SSG

ISR

Hydration

Cached background refetching

UI flicker caused by naive fetching

Both components:

call the same endpoint

refetch every few seconds

run under throttled network conditions

display live telemetry

Naive useEffect Fetching

A common pattern looks like this:

useEffect (() => { setLoading ( true );

fetch ( " /api/data " ) . then (( res ) => res . json ()) .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.