Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "local-storage-events"

Index

Functions

deleteFromStorage

  • deleteFromStorage(key: string): void
  • Use this function to delete a value from localStorage.

    After calling this function, the localStorage value will be null.

    example
    const user = { name: 'John', email: 'John@fakemail.com' };
    
    // Add a user to your localStorage
    writeStorage('user', JSON.stringify(user));
    
    // This will also trigger an update to the state of your component
    deleteFromStorage('user');
    
    localStorage.getItem('user') === null // ✔ This is now null
    export

    Parameters

    • key: string

      The key of the item you wish to delete from localStorage.

    Returns void

isTypeOfLocalStorageChanged

  • isTypeOfLocalStorageChanged<TValue>(evt: any): evt is LocalStorageChanged<TValue>
  • Checks if the event that is passed in is the same type as LocalStorageChanged.

    export

    Type parameters

    • TValue

    Parameters

    • evt: any

      the object you wish to assert as a LocalStorageChanged event.

    Returns evt is LocalStorageChanged<TValue>

    if true, evt is asserted to be LocalStorageChanged.

writeStorage

  • writeStorage<TValue>(key: string, value: TValue): void
  • Use this instead of directly using localStorage.setItem in order to correctly send events within the same window.

    example
    writeStorage('hello', JSON.stringify({ name: 'world' }));
    const { name } = JSON.parse(localStorage.getItem('hello'));
    export

    Type parameters

    • TValue

    Parameters

    • key: string

      The key to write to in the localStorage.

    • value: TValue

      The value to write to in the localStorage.

    Returns void

Generated using TypeDoc