TinyBase logoTinyBase β

useProvideCheckpoints

The useProvideCheckpoints primitive is used to add a Checkpoints object by Id to a Provider component, but imperatively from a component within it.

useProvideCheckpoints(
  checkpointsId: string,
  checkpoints: Checkpoints,
): void
TypeDescription
checkpointsIdstring

The Id of the Checkpoints object to be registered with the Provider.

checkpointsCheckpoints

The Checkpoints object to be registered.

returnsvoid

This has no return value.

Normally you will register a Checkpoints object by Id in a context by using the checkpointsById prop of the top-level Provider component. This primitive, however, lets you dynamically add a new Checkpoints object to the context, from within a component. This is useful for applications where the set of Checkpoints objects is not known at the time of the first render of the root Provider.

A Checkpoints object added to the Provider context in this way will be available to other components within the context (using the useCheckpoints primitive and so on). If you use the same Id as an existing Checkpoints object registration, the new one will take priority over one provided by the checkpointsById prop.

Example

import {createRoot} from 'solid-js';
import {createCheckpoints, createStore} from 'tinybase';
import {useProvideCheckpoints} from 'tinybase/ui-solid';

createRoot((dispose) => {
  const store = createStore().setCell('pets', 'fido', 'color', 'brown');
  const checkpoints = createCheckpoints(store);
  useProvideCheckpoints('petCheckpoints', checkpoints);
  console.log(JSON.stringify(checkpoints.getCheckpointIds()));
  // -> '[[],"0",[]]'
  dispose();
});

Since

v8.3.0