useIndexesIds
The useIndexesIds
hook is used to retrieve the Ids
of all the named Indexes
objects present in the current Provider
component context.
useIndexesIds(): Ids
Example
This example adds two named Indexes
objects to a Provider context and an inner component accesses their Ids
.
import {
Provider,
useCreateIndexes,
useCreateStore,
useIndexesIds,
} from 'tinybase/ui-react';
import {createIndexes, createStore} from 'tinybase';
import React from 'react';
import {createRoot} from 'react-dom/client';
const App = () => {
const store1 = useCreateStore(createStore);
const indexes1 = useCreateIndexes(store1, createIndexes);
const store2 = useCreateStore(createStore);
const indexes2 = useCreateIndexes(store2, createIndexes);
return (
<Provider indexesById={{indexes1, indexes2}}>
<Pane />
</Provider>
);
};
const Pane = () => <span>{JSON.stringify(useIndexesIds())}</span>;
const app = document.createElement('div');
createRoot(app).render(<App />);
console.log(app.innerHTML);
// -> '<span>["indexes1","indexes2"]</span>'
Since
v4.1.0