useCreateStore
Essential
The useCreateStore primitive is used to create a Store within a Solid application with convenient ownership.
useCreateStore(create: () => Store): Accessor<Store>| Type | Description | |
|---|---|---|
create | () => Store | A function for performing the creation of the |
| returns | Accessor<Store> | A reference to the |
It is possible to create a Store outside of the Solid app with the regular createStore function and pass it in, but you may prefer to create it within the app, perhaps inside the top-level component. The Store is created once in the current reactive owner and is disposed with that owner.
In Solid, changing values should be read inside the create function via signals or other Accessors, rather than via a dependency list.
Example
import {createRoot} from 'solid-js';
import {createStore} from 'tinybase';
import {useCreateStore} from 'tinybase/ui-solid';
createRoot((dispose) => {
const store = useCreateStore(() =>
createStore().setCell('pets', 'fido', 'species', 'dog'),
);
console.log(store().getCell('pets', 'fido', 'species'));
// -> 'dog'
dispose();
});
Since
v8.3.0