Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
TanStack DB ~状態管理の新しい考え方~
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
じょうげん
August 22, 2025
Programming
1.2k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TanStack DB ~状態管理の新しい考え方~
じょうげん
August 22, 2025
More Decks by じょうげん
See All by じょうげん
値・型・名前空間の「三重定義」で Reactコンポーネントをより柔軟に設計する TypeScript コンパニオンオブジェクト活用術
bmthd
0
97
読みやすいコードとはなにか? 未来の自分とチームへの思いやり
bmthd
0
510
Yamada UIドキュメント v2紹介
bmthd
0
760
コールバックchildrenでロジックの見通しを改善する
bmthd
0
44
Formの複雑さに立ち向かう
bmthd
1
3.5k
Other Decks in Programming
See All in Programming
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
0
270
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
270
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
170
A2UI for Android: Safely Rendering AI-Generated UI with Jetpack Compose - DroidKaigi 2026
itsmedreamwalker
0
130
スマート反転とウェブアクセシビリティ
camiha
0
210
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
680
AIエージェント時代のコードレビューを設計する
nogu66
6
2.7k
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
270
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
250
XHTMLが残したもの
yosuke_furukawa
PRO
2
800
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
699
190k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
230
How to build a perfect <img>
jonoalderson
1
6k
Evolving SEO for Evolving Search Engines
ryanjones
0
290
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
380
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
Are puppies a ranking factor?
jonoalderson
2
3.9k
Rails Girls Zürich Keynote
gr2m
96
14k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
990
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Abbi's Birthday
coloredviolet
4
10k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
880
Transcript
TanStack DB ~ 状態管理の新しい考え方~ じょうげん
TanStack Query - Server State Management TanStack Router - Type-Safe
Routing TanStack Table - Headless Table Building TanStack Form - Headless Form Building TanStack DB - Client-Side Database ← NEW! TanStack ファミリー
フロントエンドに 永続化層(DB) を設けてコンポーネントからクエリする クエリファーストなAPI React だけでなく Vue / Svelte /
Solid など多数のUI フレームワークをサポート TanStack DB とは?
Client Side Querying → データ取得の主導権をフロント側へ 設計思想
export const drawCalcCollection = createCollection( localStorageCollectionOptions({ storageKey: "tcg-tool-draw-calculations", id: "draw-calculations",
getKey: (item) => item.id, schema: drawCalcSchema }), ); Collection という単位でデータの永続化を定義 Zod やValibot などでランタイムバリデーションありの型定義可能 React での使い方の例
const { data } = useLiveQuery((q) => q .from({ calculations:
calculationsCollection }) .where(({ calculations }) => eq(calculations.id, calculationId)), ); Drizzle のようなSQL ライクなセレクター 型安全なクエリビルダー クエリで絞り込まれた箇所のみの部分的なSubscribe を実現
const CalculationItem = ({ calculationId }: { calculationId: string })
=> { const { data } = useLiveQuery((q) => q.from({ calculations: calculationsCollection }) .where(({ calculations }) => eq(calculations.id, calculationId)), ); const firstCalculation = data[0]; if (!firstCalculation) return <FallbackItem />; return ( <Card.Root> <Card.Header> {firstCalculation.name} </Card.Header> <Card.Body> {firstCalculation.result} </Card.Body> </Card.Root> ); } コンポーネントで使う
// 条件をあらかじめ指定 export const drawCalcHistoryCollection = createLiveQueryCollection((q) => q.from({ calculations:
drawCalcCollection }) .orderBy(({ calculations }) => calculations.updatedAt, "desc"), ); // 引数ありの動的なCollection export const createDrawCalcByGameCollection = (gameTemplate: string) => createLiveQueryCollection((q) => q.from({ calculations: drawCalcCollection }) .where(({ calculations }) => eq(calculations.gameTemplate, gameTemplate)) .orderBy(({ calculations }) => calculations.updatedAt, "desc"), ); 派生Collection も可能
TanStack DB 、なにが美味しい?
localStorage インメモリ REST API Electric SQL TrailBase Supabase, IndexedDB, DuckDB
Wasm などもAdapter を用意することで利用可能になる かも 永続化層を 自由に差し替え可能
フロントエンド中心のデータ設計 が可能 RLS (Row Level Security )を組み合わせれば都度問い合わせの必要なし 特定の データベースSaaS の実装に依存せずに済む
バックエンド実装が不要に?
Zustand / Jotai のような状態を → SQL ライクなクエリ + スキーマ に置き換え可能
単なる状態管理にとどまらず、データの保管にも利用できる 認知負荷を大幅に削減 できるかも! 状態管理のベストプラクティスを変える?
Claude Code と一緒に既存のアプリケ ーションをTanStack DB に載せ替えし てみた できたもの https://tcg-tool.pages.dev/ draw-calc-db
ソースコード見たい方向 け https://github.com/bmthd/ tcg-tool/pull/3/files おまけ
「フロントエンド中心のデータ設計」を加速させる存在 全てのServer State の抽象化層になりうる フロントエンドの状態管理だけでなくバックエンド設計にも影響を与える可能性 大 まとめ