Skip to content

@gtkx/react / useSetting

Function: useSetting()

useSetting<T>(schemaId, key, type): [SettingTypeMap[T], (value) => void]

Defined in: packages/react/src/use-setting.ts:68

Subscribes to a GSettings key and returns its current value alongside a setter, similar to useState.

Creates a Gio.Settings instance for the given schema (stable across re-renders), connects to changed::key, and re-renders whenever the setting changes. The initial value is read synchronously at mount time. Calling the returned setter writes the new value to GSettings, which in turn triggers a re-render through the changed signal.

Type Parameters

Type Parameter
T extends keyof SettingTypeMap

Parameters

ParameterTypeDescription
schemaIdstringThe GSettings schema ID (e.g. "org.gnome.desktop.interface")
keystringThe settings key in kebab-case (e.g. "color-scheme")
typeTThe value type, used to select the appropriate GSettings getter/setter

Returns

[SettingTypeMap[T], (value) => void]

A [value, setValue] tuple kept in sync with the GSettings backend

Examples

tsx
const [colorScheme, setColorScheme] = useSetting("org.gnome.desktop.interface", "color-scheme", "string");
tsx
const [fontSize, setFontSize] = useSetting("com.example.myapp", "font-size", "int");