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.3k
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
110
読みやすいコードとはなにか? 未来の自分とチームへの思いやり
bmthd
0
520
Yamada UIドキュメント v2紹介
bmthd
0
770
コールバックchildrenでロジックの見通しを改善する
bmthd
0
49
Formの複雑さに立ち向かう
bmthd
1
3.5k
Other Decks in Programming
See All in Programming
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
220
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.6k
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
350
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
phperだってパンチカードでコーディングしたい
o0h
PRO
0
260
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
200
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
AWSに止められる覚悟してますか?
morizo_1984
2
520
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.2k
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
580
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
560
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
Side Projects
sachag
456
43k
Building Applications with DynamoDB
mza
96
7.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
Designing for Performance
lara
612
70k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.3k
Code Review Best Practice
trishagee
74
20k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
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 の抽象化層になりうる フロントエンドの状態管理だけでなくバックエンド設計にも影響を与える可能性 大 まとめ