# RoomDefinition: data property

> The data property of a room definition is a function that makes room.data each time the room starts or wakes.

The **`data`** property of a [room definition](/docs/room/room-definition) is a function that makes `room.data`, the room's own object for what it derives or keeps in memory. It runs each time the room starts or wakes, before [`onCreate()`](/docs/room/room-definition/oncreate) or [`onWake()`](/docs/room/room-definition/onwake), and its return type types `room.data`.

## Value

A function that takes no arguments and returns an object. Without it, `room.data` starts as `{}`.

## Description

`room.data` is one plain object per room. It isn't synced to clients and isn't saved in room state, so it starts again from `data()` after every wake and after a room host restart. Build what it holds from room state in `onCreate` and again in `onWake`.

Use it, not a variable at the top level of the module, for anything that belongs to one room: a room host runs many rooms of one module, which share module variables. `room.data` can hold entity objects safely, since both are new objects after a wake.

## Examples

### Limiting chat per player

```ts
// slow-chat.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  data: () => ({ lastLine: new Map<string, number>() }),
  onMessage(room, connection, message) {
    if (typeof message !== "string") return;
    const now = room.now();
    if (now - (room.data.lastLine.get(connection.player) ?? 0) < 1000) return;
    room.data.lastLine.set(connection.player, now);
    room.broadcast({ from: connection.player, text: message.slice(0, 200) });
  },
});
```

## See also

- [Room data and module scope](/docs/room/sdk#room-data-and-module-scope)
- [`Room`](/docs/room/room)
