Fix persistence typing

This commit is contained in:
Nicolas Mowen 2024-02-28 06:53:25 -07:00
parent 9c519b9dad
commit a251f1fee6
2 changed files with 5 additions and 5 deletions

View File

@ -22,7 +22,7 @@ export default function DebugCameraImage({
cameraConfig, cameraConfig,
}: DebugCameraImageProps) { }: DebugCameraImageProps) {
const [showSettings, setShowSettings] = useState(false); const [showSettings, setShowSettings] = useState(false);
const [options, setOptions] = usePersistence( const [options, setOptions] = usePersistence<Options>(
`${cameraConfig?.name}-feed`, `${cameraConfig?.name}-feed`,
emptyObject emptyObject
); );
@ -36,7 +36,7 @@ export default function DebugCameraImage({
const searchParams = useMemo( const searchParams = useMemo(
() => () =>
new URLSearchParams( new URLSearchParams(
Object.keys(options).reduce((memo, key) => { Object.keys(options || {}).reduce((memo, key) => {
//@ts-ignore we know this is correct //@ts-ignore we know this is correct
memo.push([key, options[key] === true ? "1" : "0"]); memo.push([key, options[key] === true ? "1" : "0"]);
return memo; return memo;
@ -68,7 +68,7 @@ export default function DebugCameraImage({
<CardContent> <CardContent>
<DebugSettings <DebugSettings
handleSetOption={handleSetOption} handleSetOption={handleSetOption}
options={options} options={options || {}}
/> />
</CardContent> </CardContent>
</Card> </Card>

View File

@ -3,7 +3,7 @@ import { get as getData, set as setData } from "idb-keyval";
type usePersistenceReturn<S extends any> = [ type usePersistenceReturn<S extends any> = [
value: S | undefined, value: S | undefined,
setValue: (value: string | boolean) => void, setValue: (value: S) => void,
loaded: boolean, loaded: boolean,
]; ];
@ -15,7 +15,7 @@ export function usePersistence<S>(
const [loaded, setLoaded] = useState<boolean>(false); const [loaded, setLoaded] = useState<boolean>(false);
const setValue = useCallback( const setValue = useCallback(
(value: string | boolean) => { (value: S) => {
setInternalValue(value); setInternalValue(value);
async function update() { async function update() {
await setData(key, value); await setData(key, value);