useValueIds
The useValueIds primitive returns the Ids of every Value in a Store, and registers a listener so that any changes to that result will cause an update.
useValueIds(storeOrStoreId?: MaybeAccessor<undefined | StoreOrStoreId>): Accessor<Ids>| Type | Description | |
|---|---|---|
storeOrStoreId? | MaybeAccessor<undefined | StoreOrStoreId> | The |
| returns | Accessor<Ids> |
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 useValueIds primitive lets you indicate which Store to get data for: omit the optional parameter for the default context Store, provide an Id for a named context Store, or provide a Store explicitly by reference.
When first rendered, this primitive will create a listener so that changes to the Value Ids will cause an update. When the component containing this primitive is unmounted, the listener will be automatically removed.
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 {useValueIds} from 'tinybase/ui-solid';
createRoot((dispose) => {
const store = createStore().setValues({open: true, employees: 3});
const valueIds = useValueIds(store);
console.log(JSON.stringify(valueIds()));
// -> '["open","employees"]'
dispose();
});
Since
v8.3.0