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