@gtkx/react / useProperty
Function: useProperty()
useProperty<
T,K>(obj,propertyName):T[K] |undefined
Defined in: packages/react/src/use-property.ts:33
Subscribes to a GObject property and returns its current value as React state.
Connects to the notify::property-name signal on obj and re-renders whenever the property changes. The initial value is read synchronously at mount time. Disconnects automatically on unmount or when inputs change.
When obj is null or undefined, the hook is inactive and returns undefined. This allows safe usage with nullable objects without violating React's rules of hooks.
Type Parameters
| Type Parameter |
|---|
T extends Object |
K extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | T | null | undefined | The GObject instance to observe, or null/undefined to disable |
propertyName | K | The property name matching an ES6 accessor on the object |
Returns
T[K] | undefined
The current property value, or undefined when obj is null/undefined
Example
tsx
const app = useApplication();
const activeWindow = useProperty(app, "activeWindow");
const title = useProperty(activeWindow, "title");