insertLocalStorage
The insertLocalStorage insertion automatically synchronizes state with browser localStorage, persisting data across sessions.
Import
typescript
import { insertLocalStorage } from '@ng-angular-stack/craft';Basic Usage
typescript
const myState = state(
0,
insertLocalStoragePersister({
storeName: 'myTestStore',
key: 'myState',
}),
);
const myQuery = query(
{
params: () => 'test',
loader: async () => {
return { data: 'testData' };
},
},
insertLocalStoragePersister({
storeName: 'myTestStore',
key: 'myTestQuery',
}),
);
const myMutation = mutation(
{
method: () => 'test',
loader: async () => {
return { data: 'testData' };
},
},
insertLocalStoragePersister({
storeName: 'myTestStore',
key: 'myMutation',
}),
);
const myAsyncMethod = asyncMethod(
{
method: () => 'test',
loader: async () => {
return { data: 'testData' };
},
},
insertLocalStoragePersister({
storeName: 'myTestStore',
key: 'myAsyncMethod',
}),
);See Also
- state - Base primitive for state
- insertReactOnMutation - React to mutations
- Store - Compose insertions in stores