TinyBase logoTinyBase β

useStoreIds

The useStoreIds hook is used to retrieve the Ids of all the named Store objects present in the current Provider component context.

useStoreIds(): Ids
returnsIds

A list of the Ids in the context.

Example

This example adds two named Store objects to a Provider context and an inner component accesses their Ids.

import {Provider, useCreateStore, useStoreIds} from 'tinybase/ui-react';
import React from 'react';
import {createRoot} from 'react-dom/client';
import {createStore} from 'tinybase';

const App = () => {
  const store1 = useCreateStore(createStore);
  const store2 = useCreateStore(createStore);
  return (
    <Provider storesById={{store1, store2}}>
      <Pane />
    </Provider>
  );
};
const Pane = () => <span>{JSON.stringify(useStoreIds())}</span>;

const app = document.createElement('div');
createRoot(app).render(<App />);
console.log(app.innerHTML);
// -> '<span>["store1","store2"]</span>'

Since

v4.1.0