app/src/hooks/useExpressionById.ts

17 lines
439 B
TypeScript

import { useLiveQuery } from "dexie-react-hooks";
import { database, ItemNotFoundError } from "../model";
export function useExpressionById(expression_id: number) {
return useLiveQuery(
() =>
database.expressions
.where({ id: expression_id })
.toArray()
.then((result) => {
if (result.length === 0) return ItemNotFoundError;
return result[0];
}),
[expression_id]
);
}