AIDK API Reference / aidk/state / watchComState
Function: watchComState()
ts
function watchComState<T>(key: string, defaultValue?: T): ReadonlySignal<T | undefined>;Defined in: packages/core/src/state/use-state.ts:127
Creates a read-only signal that watches COM state.
Use this when you want to observe state that another component owns, without being able to modify it. The signal updates automatically when the COM state changes.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The COM state key to watch |
defaultValue? | T | Default value if state doesn't exist |
Returns
ReadonlySignal<T | undefined>
Example
typescript
class ObserverComponent extends Component {
// Watch timeline state owned by another component
private timeline = watchComState<COMTimelineEntry[]>('timeline');
// Can create derived values
private messageCount = computed(() => this.timeline()?.length ?? 0);
render() {
// Can read
return <div>Messages: {this.messageCount()}</div>;
// Cannot write - no .set() or .update()
// this.timeline.set([...]) // ❌ Not available
}
}