useCellState
The useCellState primitive returns a Cell from a Store and a callback to set it, following the common Solid useState convention.
useCellState(
tableId: MaybeAccessor<string>,
rowId: MaybeAccessor<string>,
cellId: MaybeAccessor<string>,
storeOrStoreId?: MaybeAccessor<undefined | StoreOrStoreId>,
): [Accessor<CellOrUndefined>, (cell: Cell) => void]| Type | Description | |
|---|---|---|
tableId | MaybeAccessor<string> | |
rowId | MaybeAccessor<string> | |
cellId | MaybeAccessor<string> | |
storeOrStoreId? | MaybeAccessor<undefined | StoreOrStoreId> | The |
| returns | [Accessor<CellOrUndefined>, (cell: Cell) => void] | A tuple containing the current |
This primitive is useful for creating components that read and write a Cell in a single line, similar to how you would use Solid's useState primitive.
The component this is used in will update when the Cell changes.
Example
This example creates a Store, binds it to the primitive, and reads the resulting Solid Accessor.
import {createRoot} from 'solid-js';
import {createStore} from 'tinybase';
import {useCellState} from 'tinybase/ui-solid';
createRoot((dispose) => {
const store = createStore();
const [cell, setCell] = useCellState('pets', 'fido', 'species', store);
setCell('dog');
console.log(cell());
// -> 'dog'
dispose();
});
Since
v8.3.0