TinyBase logoTinyBase β

Provider

Essential

The Provider component is used to wrap part of an application in a context that provides default objects to be used by primitives and components within.

Provider(props: (
  ProviderProps &
  {children: Element}
)): ComponentReturnType
TypeDescription
props( ProviderProps & {children: Element} )

The props for this component.

returnsComponentReturnType

A rendering of the child components.

Store, Metrics, Indexes, Relationships, Queries, Checkpoints, Persister, and Synchronizer objects can be passed into the context of an application and used throughout. One of each type of object can be provided as a default within the context. Additionally, multiple of each type of object can be provided in an Id-keyed map to the ___ById props.

Provider contexts can be nested and the objects passed in will be merged. For example, if an outer context contains a default Metrics object and an inner context contains only a default Store, both the Metrics objects and the Store will be visible within the inner context. If the outer context contains a Store named by Id and the inner context contains a Store named by a different Id, both will be visible within the inner context.

Example

import {createRoot} from 'solid-js';
import {createStore} from 'tinybase';
import {Provider} from 'tinybase/ui-solid';

createRoot((dispose) => {
  const store = createStore().setCell('pets', 'fido', 'species', 'dog');
  const provider = Provider({store, children: 'content'});
  console.log(typeof provider);
  // -> 'function'
  dispose();
});

Since

v8.3.0