settings: convert flashCurrentProgram to react hook

This commit is contained in:
David Lechner
2022-03-15 16:54:49 -05:00
parent d18ad41e39
commit 861ea34d86
13 changed files with 100 additions and 217 deletions
+9 -1
View File
@@ -1,9 +1,12 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
import { useCallback } from 'react';
import { Dispatch, SetStateAction, useCallback } from 'react';
import { useLocalStorage } from 'usehooks-ts';
// this is private type from usehooks-ts
type SetValue<T> = Dispatch<SetStateAction<T>>;
/** Hook for "showDocs" setting. */
export function useSettingIsShowDocsEnabled(): {
isSettingShowDocsEnabled: boolean;
@@ -26,3 +29,8 @@ export function useSettingIsShowDocsEnabled(): {
toggleIsSettingShowDocsEnabled,
};
}
/** Hook for "flashCurrentProgram" setting. */
export function useSettingFlashCurrentProgram(): [boolean, SetValue<boolean>] {
return useLocalStorage<boolean>('setting.flashCurrentProgram', false);
}