# Cursor

**Kind:** Class

Model class containing information about the state of the user's current interactions in
Airtable - specifically, their active table, active view, selected records and selected fields.
Also allows you to set the active table and active view.

Selected records and fields are not loaded by default and the cursor must be loaded with
`useLoadable` to access them.

```js
import {useCursor, useWatchable} from '@airtable/blocks/ui';

 function ActiveTableAndView() {
     const cursor = useCursor();

     return (
         <div>
             Active table: {cursor.activeTableId}
             <br />
             Active view: {cursor.activeViewId}
         </div>
     );
 }
```

```js
import {useCursor, useLoadable, useWatchable} from '@airtable/blocks/ui';

 function SelectedRecordAndFieldIds() {
     const cursor = useCursor();
     // load selected records and fields
     useLoadable(cursor);

     // re-render whenever the list of selected records or fields changes
     useWatchable(cursor, ['selectedRecordIds', 'selectedFieldIds']);

     return (
         <div>
             Selected records: {cursor.selectedRecordIds.join(', ')}
             <br />
             Selected fields: {cursor.selectedFieldIds.join(', ')}
         </div>
     );
 }
```

## Properties

### `activeTableId`

Type: `TableId | null`

The currently active table ID. Can be null when the active table has changed and is not yet
loaded, and can also refer to a table that is not yet loaded.

When fetching the `Table`, use `base.getTableByIdIfExists(cursor.activeTableId)` and
check the return value is not `null` to be resilient to those cases.

Can be watched.

### `activeViewId`

Type: `ViewId | null`

The currently active view ID. This will always be a view belonging to `activeTableId`. Can be
null when the active view has changed and is not yet loaded, and can also refer to a view
that is not yet loaded.

When fetching the `View`, use `table.getViewByIdIfExists(cursor.activeViewId)` and
check the return value is not `null` to be resilient to those cases.

Can be watched.

### `id`

Type: `string`

The ID for this model.

### `isDataLoaded`

Type: `boolean`

### `isDeleted`

Type: `boolean`

### `selectedFieldIds`

Type: `Array<RecordId>`

The field IDs of all currently selected fields, or an empty array if no fields are selected.

Not loaded by default: you must load cursor data with `useLoadable(cursor)` (recommended) or
`cursor.loadDataAsync()` before use.

Can be watched.

### `selectedRecordIds`

Type: `Array<RecordId>`

The record IDs of all currently selected records, or an empty array if no records are selected.

Not loaded by default. You must load cursor data with `useLoadable(cursor)` (recommended) or
`cursor.loadDataAsync()` before use.

Can be watched.

## Methods

### `isRecordSelected(recordOrRecordId)`

Checks whether a given record is selected.

Selected records are not loaded by default. You must load cursor data with
`useLoadable(cursor)` (recommended) or `cursor.loadDataAsync()` before use.

**Parameters:**
- `recordOrRecordId` (`Record | string`) — The record or record ID to check for.

**Returns:** `boolean`

### `loadDataAsync()`

Will cause all the async data to be fetched and retained. Every call to
`loadDataAsync` should have a matching call to `unloadData`.

Returns a Promise that will resolve once the data is loaded.

**Returns:** `Promise<void>`

### `setActiveTable(tableOrTableId)`

Sets the specified table to active in the Airtable UI. If the extension installation or extensions pane
is fullscreen, fullscreen mode will be exited.

**Parameters:**
- `tableOrTableId` (`Table | TableId`) — The target table or table ID to set as active in the Airtable main page.

**Returns:** `void`

### `setActiveView(tableOrTableId, viewOrViewId)`

Sets the specified view (and corresponding table) to active in the Airtable UI. If the extension
installation or extensions pane is fullscreen, fullscreen mode will be exited.

**Parameters:**
- `tableOrTableId` (`Table | TableId`) — The table or table ID that the target view belongs to.
- `viewOrViewId` (`View | ViewId`) — The target view or view ID to set as active in the Airtable main page.

**Returns:** `void`

### `toString()`

A string representation of the model for use in debugging.

**Returns:** `string`

### `unloadData()`

**Returns:** `void`

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

Unwatching a key that needs to load data asynchronously will automatically
cause the data to be released. Once the data is available, the callback
will be called.

**Parameters:**
- `keys` (`WatchableCursorKey | ReadonlyArray<WatchableCursorKey>`)
- `callback` (`FlowAnyFunction`)
- `context?` (`FlowAnyObject | null`)

**Returns:** `Array<WatchableCursorKey>`

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

Watching a key that needs to load data asynchronously will automatically
cause the data to be fetched. Once the data is available, the callback
will be called.

**Parameters:**
- `keys` (`WatchableCursorKey | ReadonlyArray<WatchableCursorKey>`)
- `callback` (`FlowAnyFunction`)
- `context?` (`FlowAnyObject | null`)

**Returns:** `Array<WatchableCursorKey>`
