feat(07-01): create useWeightUnit convenience hook
- Wraps useSetting("weightUnit") with typed WeightUnit return
- Validates stored value against known units (g, oz, lb, kg)
- Defaults to "g" when no setting exists (backward compatible)
- Fix config.json formatting (tabs per biome config)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
12
src/client/hooks/useWeightUnit.ts
Normal file
12
src/client/hooks/useWeightUnit.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { WeightUnit } from "../lib/formatters";
|
||||
import { useSetting } from "./useSettings";
|
||||
|
||||
const VALID_UNITS: WeightUnit[] = ["g", "oz", "lb", "kg"];
|
||||
|
||||
export function useWeightUnit(): WeightUnit {
|
||||
const { data } = useSetting("weightUnit");
|
||||
if (data && VALID_UNITS.includes(data as WeightUnit)) {
|
||||
return data as WeightUnit;
|
||||
}
|
||||
return "g";
|
||||
}
|
||||
Reference in New Issue
Block a user