A set of utils to get, set, clear and remove localStorage data.

Methods

(inner) clear() → {void}

Remove all entries from localStorage.

Since
  • 1.0.0
Returns:
Type: 
void
Example
import { localStorage } from "@gravityforms/utils";

function Example() {
    localStorage.clear();
};

(inner) get(key) → {string|null}

Get an entry from localStorage.

Parameters:
NameTypeDescription
keystring

The local storage key.

Since
  • 1.0.0
Returns:

The data as string for the key, or undefined.

Type: 
string | null
Example
import { localStorage } from "@gravityforms/utils";

function Example() {
    const data = localStorage.get( 'my-key' );
    if ( data ) {
        console.log( JSON.parse( data ) );
    }
};

(inner) put(key, value) → {void}

Put an entry into localStorage.

Parameters:
NameTypeDescription
keystring

The local storage key.

valuestring

The local storage value.

Since
  • 1.0.0
Returns:
Type: 
void
Example
import { localStorage } from "@gravityforms/utils";

function Example() {
    const data = {
        some: 'thing',
        even: 'more',
    };
    localStorage.put( 'my-key', JSON.stringify( data ) );
};

(inner) remove(key) → {void}

Remove an entry from localStorage.

Parameters:
NameTypeDescription
keystring

The local storage key.

Since
  • 1.0.0
Returns:
Type: 
void
Example
import { localStorage } from "@gravityforms/utils";

function Example() {
    localStorage.remove( 'my-key' );
};