# Base

**Kind:** Class

Model class representing a base.

If you want the base model to automatically recalculate whenever the base schema changes, try the
`useBase` hook.

## Properties

### `activeCollaborators`

Type: `Array<CollaboratorData>`

The users who have access to this base.

```js
import {useBase} from '@airtable/blocks/interface/ui';

function MyApp() {
    const base = useBase();
    console.log(base.activeCollaborators[0].email);
}
```

### `color`

Type: `string`

The color of the base.

```js
import {colorUtils, useBase} from '@airtable/blocks/interface/ui';

function MyApp() {
    const base = useBase();
    return (
        <div style={{backgroundColor: colorUtils.getHexForColor(base.color)}}>
            This div's background is the same color as the base background
        </div>
    );
}
```

### `id`

Type: `string`

The ID for this model.

### `isDeleted`

Type: `boolean`

`true` if the model has been deleted, and `false` otherwise.

In general, it's best to avoid keeping a reference to an object past the
current event loop, since it may be deleted and trying to access any data
of a deleted object (other than its ID) will throw. But if you keep a
reference, you can use `isDeleted` to check that it's safe to access the
model's data.

### `name`

Type: `string`

The name of the base.

```js
import {useBase} from '@airtable/blocks/interface/ui';

function MyApp() {
    const base = useBase();
    console.log('The name of your base is', base.name);
}
```

### `tables`

Type: `Array<Table>`

The tables in this base. Can be watched to know when tables are created, deleted, or reordered in the base.

```js
import {useBase} from '@airtable/blocks/interface/ui';

function MyApp() {
    const base = useBase();
    console.log(`You have ${base.tables.length} tables`);
}
```

### `workspaceId`

Type: `string`

The workspace id of the base.

```js
import {useBase} from '@airtable/blocks/interface/ui';

function MyApp() {
    const base = useBase();
    console.log('The workspace id of your base is', base.workspaceId);
}
```

## Methods

### `getCollaborator(idOrNameOrEmail)`

The user matching the given ID, name, or email address. Throws if that user does not exist
or does not have access to this base. Use `getCollaboratorIfExists` instead if you are
unsure whether a collaborator with the given ID exists and has access to this base.

This method is convenient when building an extension for a specific base, but for more generic
extensions the best practice is to use the `getCollaboratorById` method instead.

**Parameters:**
- `idOrNameOrEmail` (`UserId | string`)

**Returns:** `CollaboratorData | null`

### `getCollaboratorById(collaboratorId)`

The user matching the given ID. Throws if that user does not exist
or does not have access to this base. Use `getCollaboratorByIdIfExists`
instead if you are unsure whether a collaborator with the given ID exists
and has access to this base.

**Parameters:**
- `collaboratorId` (`UserId`) — The ID of the user.

**Returns:** `CollaboratorData`

### `getCollaboratorByIdIfExists(collaboratorId)`

The user matching the given ID, or `null` if that user does not exist or does not have access
to this base.

**Parameters:**
- `collaboratorId` (`UserId`) — The ID of the user.

**Returns:** `CollaboratorData | null`

### `getCollaboratorIfExists(idOrNameOrEmail)`

The user matching the given ID, name, or email address. Returns null if that user does not
exist or does not have access to this base.

This method is convenient when building an extension for a specific base, but for more generic
extensions the best practice is to use the `getCollaboratorByIdIfExists` method instead.

**Parameters:**
- `idOrNameOrEmail` (`UserId | string`)

**Returns:** `CollaboratorData | null`

### `getMaxRecordsPerTable()`

Returns the maximum number of records allowed in each table of this base.

**Returns:** `number`

### `getTable(tableIdOrName)`

The table matching the given ID or name. Throws if no matching table exists within this base.
Use `getTableIfExists` instead if you are unsure whether a table exists with the given
name/ID.

This method is convenient when building an extension for a specific base, but for more generic
extensions the best practice is to use the `getTableById` or `getTableByName` methods
instead.

**Parameters:**
- `tableIdOrName` (`TableId | string`) — The ID or name of the table you're looking for.

**Returns:** `Table`

### `getTableById(tableId)`

The table matching the given ID. Throws if that table does not exist in this base. Use
`getTableByIdIfExists` instead if you are unsure whether a table exists with the given
ID.

**Parameters:**
- `tableId` (`string`) — The ID of the table.

**Returns:** `Table`

### `getTableByIdIfExists(tableId)`

The table matching the given ID, or `null` if that table does not exist in this base.

**Parameters:**
- `tableId` (`string`) — The ID of the table.

**Returns:** `Table | null`

### `getTableByName(tableName)`

The table matching the given name. Throws if no table exists with that name in this base. Use
`getTableByNameIfExists` instead if you are unsure whether a table exists with the
given name.

**Parameters:**
- `tableName` (`string`) — The name of the table you're looking for.

**Returns:** `Table`

### `getTableByNameIfExists(tableName)`

The table matching the given name, or `null` if no table exists with that name in this base.

**Parameters:**
- `tableName` (`string`) — The name of the table you're looking for.

**Returns:** `Table | null`

### `getTableIfExists(tableIdOrName)`

The table matching the given ID or name. Returns `null` if no matching table exists within
this base.

This method is convenient when building an extension for a specific base, but for more generic
extensions the best practice is to use the `getTableByIdIfExists` or
`getTableByNameIfExists` methods instead.

**Parameters:**
- `tableIdOrName` (`TableId | string`) — The ID or name of the table you're looking for.

**Returns:** `Table | null`

### `toString()`

A string representation of the model for use in debugging.

**Returns:** `string`

### `unwatch(keys, callback, context?)`

Unwatch keys watched with `.watch`.

Should be called with the same arguments given to `.watch`.

Returns the array of keys that were unwatched.

**Parameters:**
- `keys` (`WatchableBaseKey | ReadonlyArray<WatchableBaseKey>`) — the keys to unwatch
- `callback` (`object`) — the function passed to `.watch` for these keys
- `context?` (`FlowAnyObject | null`) — the context that was passed to `.watch` for this `callback`

**Returns:** `Array<WatchableBaseKey>`

### `watch(keys, callback, context?)`

Get notified of changes to the model.

Every call to `.watch` should have a matching call to `.unwatch`.

Returns the array of keys that were watched.

**Parameters:**
- `keys` (`WatchableBaseKey | ReadonlyArray<WatchableBaseKey>`) — the keys to watch
- `callback` (`object`) — a function to call when those keys change
- `context?` (`FlowAnyObject | null`) — an optional context for `this` in `callback`.

**Returns:** `Array<WatchableBaseKey>`
