useSetting
HOOK

HOOKS & API / OPTIONS

useSetting

Read and update a single deskpack.json options entry straight from interactive widget controls, staying two-way synced with Deskset's right-click Edit Widget panel.

Signature#

SIGNATURE
function useSetting<T = any>(
  key: string,
  fallback: T
): [T, (next: T) => void]

Parameters#

keystringRequired
Option key declared under options in deskpack.json. Cannot start with appearance. or desktop..
fallbackTRequired
Fallback value returned if the option has no resolved value yet.

Return Value#

valueTTuple [0]
Current resolved value of the option.
setValuefunctionTuple [1]
Call setValue(next) to persist a new option value, validated automatically against the manifest type, choices, and min/max bounds.

Example: Toggle Display Mode Right on the Desktop#

Pair with a choice option named "mode" (["compact", "detailed"]) in deskpack.json:

TSX
import React, { Segmented, Spacer, Text, VStack, useSetting, useWidget } from "deskset-react";

export default function ModeSwitchWidget() {
  const { theme, t } = useWidget();
  const [mode, setMode] = useSetting<string>("mode", "compact");

  return (
    <VStack
      maxWidth={true}
      maxHeight={true}
      padding={16}
      spacing={10}
      background={theme.isPure ? "clear" : "theme.card"}
      cornerRadius={theme.isPure ? 0 : theme.corner}
      clip={!theme.isPure}
    >
      <Segmented
        value={mode}
        onChange={setMode}
        options={[
          { id: "compact", label: t("精简", "Compact") },
          { id: "detailed", label: t("详细", "Detailed") },
        ]}
      />
      <Spacer />
      <Text fontSize={14} color="theme.ink">
        {mode === "detailed"
          ? t("展示全部指标与历史趋势", "Showing full metrics & history")
          : t("仅展示核心数值", "Showing headline figure only")}
      </Text>
    </VStack>
  );
}

useSetting vs useStorage#

  • useSetting: Best for user preferences that should also be editable from the right-click Edit Widget sheet (goal, city, accent color, display mode).
  • useStorage: Best for internal runtime data (todo items, daily streaks, cached API payloads) that shouldn't clutter the settings form.