TinyBase logoTinyBase β

getCell

The getCell function returns a reactive object reflecting the value of a Cell in a Row in a Table, and registers a listener so that any changes to that Cell will update current.

getCell(
  tableId: MaybeGetter<string>,
  rowId: MaybeGetter<string>,
  cellId: MaybeGetter<string>,
  storeOrStoreId?: MaybeGetter<undefined | StoreOrStoreId>,
): {current: CellOrUndefined}
TypeDescription
tableIdMaybeGetter<string>

The Id of the Table (or a getter returning it).

rowIdMaybeGetter<string>

The Id of the Row (or a getter returning it).

cellIdMaybeGetter<string>

The Id of the Cell (or a getter returning it).

storeOrStoreId?MaybeGetter<undefined | StoreOrStoreId>

The Store to use (plain value or getter), or its Id.

returns{current: CellOrUndefined}

A reactive object with gettable and settable current.

Since Cells are mutable leaf values in a Store, the returned object's current property can also be assigned to write back to the Store.

Example

This example uses the getCell function to display a Cell value reactively.

// In a .svelte file:
// const store = createStore().setCell('pets', 'cat', 'name', 'Fido');
// const name = getCell('pets', 'cat', 'name', store);
// $: console.log(name.current); // 'Fido'

Since

v8.1.0