useRowState
The useRowState primitive returns a Row and a function to set it, following the same pattern as Solid's createSignal convention.
useRowState(
tableId: MaybeAccessor<string>,
rowId: MaybeAccessor<string>,
storeOrStoreId?: MaybeAccessor<undefined | StoreOrStoreId>,
): [Accessor<Row>, (row: Row) => void]| Type | Description | |
|---|---|---|
tableId | MaybeAccessor<string> | |
rowId | MaybeAccessor<string> | |
storeOrStoreId? | MaybeAccessor<undefined | StoreOrStoreId> | The |
| returns | [Accessor<Row>, (row: Row) => void] | An array containing the |
This is a convenience primitive that combines the useRow and useSetRowCallback primitives. It's useful when you need both read and write access to a Row in a single component.
A Provider component is used to wrap part of an application in a context, and it can contain a default Store or a set of Store objects named by Id. The useRowState primitive lets you indicate which Store to use: omit the final parameter for the default context Store, provide an Id for a named context Store, or provide a Store explicitly by reference.
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 {useRowState} from 'tinybase/ui-solid';
createRoot((dispose) => {
const store = createStore();
const [row, setRow] = useRowState('pets', 'fido', store);
setRow({species: 'dog'});
console.log(JSON.stringify(row()));
// -> '{"species":"dog"}'
dispose();
});
Since
v8.3.0