TinyBase logoTinyBase β

useCell

The useCell hook 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.

useCell(
  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 a current CellOrUndefined property.

Example

This example uses the useCell hook to display a Cell value reactively.

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

Since

v8.1.0