[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/flow](../../README) / [index](../README) / shared

# Function: shared()

> **shared**(`channel`): (`value`, `context`) => `void`

Defined in: [flow/src/decorators.ts:565](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/decorators.ts#L565)

Binds a field to convergent, server-authoritative shared state on a broadcast channel.

## Parameters

### channel

[`SharedChannel`](../type-aliases/SharedChannel)

The channel name, or a resolver over the component instance.

## Returns

A field decorator that registers the shared-state binding.

(`value`, `context`) => `void`

## Remarks

Mutating the field inside an action writes to a per-channel room store and broadcasts to the
channel, so every other subscriber's component re-reads and converges (last-write-wins). The
channel resolves per-instance (a static string, or `(self) => string` for dynamic rooms) — the
same shape as [presence](presence), so one "room" channel can carry both who's-here (`@presence`)
and shared state (`@shared`). Serialized and read-only client-side (like `@locked`): clients
render it but can only change it through `@expose` actions. Applies to a field only.

## Example

```tsx
class Whiteboard extends Component {
  @shared((self) => `board.${self.boardId}`)
  strokes: Stroke[] = [];

  @locked boardId = "";

  @expose addStroke(stroke: Stroke) {
    this.strokes = [...this.strokes, stroke]; // broadcasts to every subscriber
  }
}
```
