Skip to content

API Reference / @gtkx/react / index / useSignal

Function: useSignal()

useSignal<T, S>(object, signal, handler, options?): void

Defined in: hooks/use-signal.d.ts:33

Connects a handler to a GObject signal for the lifetime of the component, reconnecting when the object changes.

Each emission runs the handler from the latest render, so it does not have to be stable and a changing handler never reconnects the signal.

On React 19.2 this does not hold inside a component wrapped in memo or forwardRef, where every emission runs the handler captured on the first render. Keep the calling component unwrapped, or read the values the handler needs off the GObject itself. React fixes this on the 19.3 line.

Type Parameters

T

T extends Object

S

S extends string

Parameters

object

RefProp<T>

signal

S

The signal name, optionally with a ::detail suffix.

handler

TypedSignalHandler<T, S>

options?

UseSignalOptions

isAfter runs the handler after the default handler; isImmediate also invokes it on connect.

Returns

void

Released under the MPL-2.0 License.