TinyBase logoTinyBase β

useHasRow

The useHasRow primitive returns a boolean indicating whether a given Row exists in the Store, and registers a listener so that any changes to that result will cause an update.

useHasRow(
  tableId: MaybeAccessor<string>,
  rowId: MaybeAccessor<string>,
  storeOrStoreId?: MaybeAccessor<undefined | StoreOrStoreId>,
): Accessor<boolean>
TypeDescription
tableIdMaybeAccessor<string>

The Id of the Table in the Store.

rowIdMaybeAccessor<string>

The Id of the Row in the Table.

storeOrStoreId?MaybeAccessor<undefined | StoreOrStoreId>

The Store to be accessed: omit for the default context Store, provide an Id for a named context Store, or provide an explicit reference.

returnsAccessor<boolean>

Whether a Row with that Id exists in that Table.

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 useHasRow 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 Row 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 {useHasRow} from 'tinybase/ui-solid';

createRoot((dispose) => {
  const store = createStore().setCell('pets', 'fido', 'species', 'dog');
  const hasFido = useHasRow('pets', 'fido', store);
  console.log(hasFido());
  // -> true
  dispose();
});

Since

v8.3.0