TinyBase logoTinyBase β

useCheckpointsIds

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

useCheckpointsIds(): Ids
returnsIds

A list of the Ids in the context.

Example

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

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

const App = () => {
  const store1 = useCreateStore(createStore);
  const checkpoints1 = useCreateCheckpoints(store1, createCheckpoints);
  const store2 = useCreateStore(createStore);
  const checkpoints2 = useCreateCheckpoints(store2, createCheckpoints);
  return (
    <Provider checkpointsById={{checkpoints1, checkpoints2}}>
      <Pane />
    </Provider>
  );
};
const Pane = () => <span>{JSON.stringify(useCheckpointsIds())}</span>;

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

Since

v4.1.0