Universal DevTools Kit SDK / @u-devtools/kit / vanilla / useBridgeState
Function: useBridgeState()
useBridgeState<
T>(syncedState,onChange?):VanillaRef<T>
Defined in: vanilla.ts:200
Vanilla JS equivalent of useBridgeState. Creates a reactive variable with automatic synchronization.
Type Parameters
| Type Parameter | Description |
|---|---|
T | State value type |
Parameters
| Parameter | Type | Description |
|---|---|---|
syncedState | SyncedState<T> | State from core (bridge.state(...)) |
onChange? | (value) => void | (Optional) Effect function called on every change. Called immediately on initialization (immediate: true). |
Returns
VanillaRef<T>
VanillaRef object with value and dispose
Example
typescript
const count = useBridgeState(bridge.state('cnt', 0), (val) => {
button.textContent = `Count: ${val}`;
});
button.onclick = () => count.value++; // Updates both locally and in bridge