# RoomClient: update event

> The update event of the RoomClient interface fires when the client has applied a whole state update.

The **`update`** event of the [`RoomClient`](/docs/client/room-client) interface fires when the client has applied a whole state update from the room.

## Syntax

```ts
addEventListener("update", (event) => {})
```

## Event type

A `CustomEvent` whose `detail` is an object with these properties:

`update`
: A number. The state update's number.

`tick` Optional
: A number. The tick the state update is from, in a room with ticks. Absent in a room without ticks.

## Description

The room sends a state update only when something this client sees changed, so a room where nothing changes fires no `update`. For the room's current tick, use [`serverTick()`](/docs/client/room-client/servertick), not the last update's `tick`.

`update` fires after the update's entity events, such as [`onEnter()`](/docs/client/entity-store/onenter) and [`onChange()`](/docs/client/entity-store/onchange) callbacks, have run. The full state update that ends a connect or reconnect fires an [`open` event](/docs/client/room-client/open-event), or a [`wake` event](/docs/client/room-client/wake-event) after a sleep, then `update`.

## Examples

### Redrawing a scoreboard

A scoreboard redraws once per state update rather than once per changed field.

```ts
// scoreboard.ts
import { connect, defineSchema, entity } from "@irtio/client";

const Match = entity("match", { red: "u16", blue: "u16" });
const schema = defineSchema({ state: Match });

const room = await connect("https://rooms.irt.io/my-game/final", { schema });
const score = document.querySelector("#score")!;

room.addEventListener("update", (event) => {
  score.textContent = `${room.state.red} : ${room.state.blue}`;
  if (event.detail.tick !== undefined) score.setAttribute("data-tick", `${event.detail.tick}`);
});
```

## See also

- [`EntityStore`](/docs/client/entity-store), for callbacks per entity
- [`RoomClient.serverTick()`](/docs/client/room-client/servertick)
- [State sync](/docs/room/guides/state-sync#on-the-client), for what the client receives
