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

Methods

(inner) clear() → {void}

Remove all entries from sessionStorage.

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

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

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

Get an entry from sessionStorage.

Parameters:
NameTypeDescription
keystring

The session storage key.

Since
  • 1.0.0
Returns:

The data as string for the key, or undefined.

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

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

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

Put an entry into sessionStorage.

Parameters:
NameTypeDescription
keystring

The session storage key.

valuestring

The session storage value.

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

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

(inner) remove(key) → {void}

Remove an entry from sessionStorage.

Parameters:
NameTypeDescription
keystring

The session storage key.

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

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