---
title: "Using React Query with Next.js App Router and Supabase Cache Helpers"
description: "React Query can be paired with supabase-js in a Next.js App Router app by wrapping the root layout in a client-side QueryClientProvider and creating typed browser and server Supabase clients via @supabase/ssr."
url: "https://swe.quest/articles/using-react-query-with-next-js-app-router-and-supabase-cache-helpers-aaf0cb6afda9d12f"
canonical: "https://supabase.com/blog/react-query-nextjs-app-router-cache-helpers"
source: "Supabase"
published: "2024-01-12"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["react","frontend","caching","typescript"]
---

# Using React Query with Next.js App Router and Supabase Cache Helpers

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2024-01-12, 7 min read, How-to. Original: [https://supabase.com/blog/react-query-nextjs-app-router-cache-helpers](https://supabase.com/blog/react-query-nextjs-app-router-cache-helpers)

## Summary

React Query can be paired with supabase-js in a Next.js App Router app by wrapping the root layout in a client-side QueryClientProvider and creating typed browser and server Supabase clients via @supabase/ssr. Supabase Cache Helpers generate query keys automatically from supabase-js queries, so one reusable query function can be prefetched in a server component and hydrated through HydrationBoundary, letting the client render without a loading state, or fetched purely client-side. The recommendation is to reach for React Query with Server Components only when migrating an existing React Query app or when it covers needs the framework doesn't; otherwise start with the framework's own data fetching.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [React](https://swe.quest/tags/react.md) (Web & mobile)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Caching](https://swe.quest/tags/caching.md) (Backend & APIs)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)

## Prerequisites

- Next.js App Router ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))
- React hooks ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))
- Server vs client components

## Keywords

TanStack Query, React Query, Next.js, Supabase, Supabase Cache Helpers, supabase-js, @supabase/ssr

## Related posts

- [Fetching and caching Supabase data in Next.js 13 Server Components](https://swe.quest/articles/fetching-and-caching-supabase-data-in-next-js-13-server-components-3caa6b52da5f9612.md): Supabase · 2022-11-17 · Medium · 11 min read · React, Frontend, Caching, Real-time systems
  Next.js 13's app directory lets async Server Components query Supabase directly, with caching controlled by an exported \`revalidate\` value instead of separate getStaticProps/getServerSideProps functions.
- [Supabase is now compatible with Next.js 14](https://swe.quest/articles/supabase-is-now-compatible-with-next-js-14-76a3d4ceac89740e.md): Supabase · 2023-11-01 · Medium · 4 min read · React, Frontend, Identity & auth, JavaScript
  Supabase works across every Next.js 14 rendering context, including App Router Client and Server Components, Route Handlers, Server Actions and Middleware, plus the Pages Router data-fetching functions.
- [Introducing @supabase/server](https://swe.quest/articles/introducing-supabase-server-014f7e505754650d.md): Supabase · 2026-05-06 · Medium · 8 min read · Identity & auth, Serverless, TypeScript, Developer tools
  @supabase/server, now in public beta, replaces the repeated setup code found across 25,000 analyzed Edge Functions: client creation, JWT verification, claims parsing, CORS and auth wiring.
- [Infinite scroll with Next.js, Framer Motion, and Supabase](https://swe.quest/articles/infinite-scroll-with-next-js-framer-motion-and-supabase-6453fe47f3aef6ee.md): Supabase · 2023-04-04 · Medium · 8 min read · React, Frontend, JavaScript
  Infinite scroll can be built in Next.js by server-rendering the first 20 rows via getServerSideProps, then loading further pages from Supabase with offset-based .range() queries as the user nears the bottom of the list.
- [Using Supabase in Replit](https://swe.quest/articles/using-supabase-in-replit-72c3911510319276.md): Supabase · 2021-03-11 · Medium · 3 min read · JavaScript, Databases, PostgreSQL
  Supabase can serve as a hosted Postgres database for Node.js repls on Replit, queried directly through supabase-js.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
