useTablesState
The useTablesState primitive returns a Tables object and a function to set it, following the same pattern as Solid's createSignal convention.
useTablesState(storeOrStoreId?: MaybeAccessor<undefined | StoreOrStoreId>): [Accessor<Tables>, (tables: Tables) => void]| Type | Description | |
|---|---|---|
storeOrStoreId? | MaybeAccessor<undefined | StoreOrStoreId> | The |
| returns | [Accessor<Tables>, (tables: Tables) => void] | An array containing the |
This is a convenience primitive that combines the useTables and useSetTablesCallback primitives. It's useful when you need both read and write access to all Tables 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 useTablesState primitive lets you indicate which Store to use: omit the 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 {useTablesState} from 'tinybase/ui-solid';
createRoot((dispose) => {
const store = createStore();
const [tables, setTables] = useTablesState(store);
setTables({pets: {fido: {species: 'dog'}}});
console.log(JSON.stringify(tables()));
// -> '{"pets":{"fido":{"species":"dog"}}}'
dispose();
});
Since
v8.3.0