kstack-tanstack-db

Installation
SKILL.md

kstack-tanstack-db

TanStack DB の live query を書くときの規約。理由を理解した上で適用すること。useLiveQuery を置く場所(view の hook の中)は kstack-react の SKILL を参照。

無効化は query ごと undefined にし、where には常に完全な式を渡す

入力が揃わないときは、先頭のガード句で query ごと undefined を返して無効化する。条件に応じて .where() を足し引きして query の形を変えず、.where() には常に完全な式を渡す。任意の条件も、どの分岐でも完全な式を返し、and() で合成する。

// Bad: where の中で undefined を返している。undefined は式ではないので InvalidWhereExpressionError で throw する
useLiveQuery({
  query: (q) =>
    q.from({ todo: todos }).where(({ todo }) => {
      if (userId === null) {
        return undefined;
      }
      return eq(todo.userId, userId);
    }),
});
Installs
13
First Seen
12 days ago