react-state-rxjs
  • Introduction
  • Main differences
  • Performance first
  • GETTING STARTED
    • Instalation
    • Examples
  • Core concepts
    • Main idea
      • More complex flow visualization
    • Configuration
    • Store
      • Operators
      • Optimistic updates plugin
      • Form manager plugin
        • ShouldUpdateState hook
        • Custom form elements
      • Persist state plugin
        • Configuring custom storage
    • Actions
      • Immer
      • ImutableJs
      • Async
    • Components with Actions
    • @InjectStore decorator
    • @ComponentState decorator
    • ComponentState Hook
    • Dispatcher
    • Router / History
  • DIFFERENT SCENARIOS
    • Passing list item index via router
  • UNIT TESTING
    • Setup
    • Test store
    • Test actions
    • Test component with actions
    • Test with Enzyme
  • Debugging
    • Setup
    • Redux DevTools
    • Automated changes output
    • Manual state changes check
    • Additional debugging information
  • Production
    • Production mode
  • Other information
    • Best practices
    • CLI
      • Custom Configurations
    • Performance
    • Blog Posts
    • Contributing
Powered by GitBook
On this page

Was this helpful?

  1. Core concepts
  2. Store
  3. Persist state plugin

Configuring custom storage

By default localStorage is used. However you can define other storages in one of two ways:

  • Setting it globally by calling PersistStateManager.configureStorage({...}) - passed object should contain clear, getItem, removeItem, setItem methods and method to gather keys from storage () => Object.keys(sessionStorage)

PersistStateManager.configureStorage({
    clear: () => timer(2000).pipe(tap(_ => localStorage.clear())),
    getItem: (key: string) => timer(2000).pipe(map(_ => localStorage.getItem(key))),
    removeItem: (key: string) => timer(2000).pipe(tap(_ => localStorage.removeItem(key))),
    setItem: (key: string, value: any) => timer(2000).pipe(tap(_ => localStorage.setItem(key, value))),
    }, () => timer(2000).pipe(map(_ => Object.keys(localStorage))));
  • passing to params when calling save method for example:

this.store.select(['todos']).storage.save({ 
    storageConfig: { 
        storage: sessionStorage, getKeys: Object.keys(sessionStorage) 
        } 
    });

PreviousPersist state pluginNextActions

Last updated 6 years ago

Was this helpful?