A set of utils to get, set, clear and remove localStorage data.
- Source
Methods
(inner) clear() → {void}
Remove all entries from sessionStorage.
- Since
- 1.0.0
- Source
Returns:
- Type:
- void
Example
import { sessionStorage } from "@gravityforms/utils";
function Example() {
sessionStorage.clear();
};
(inner) get(key) → {string|null}
Get an entry from sessionStorage.
Parameters:
Name | Type | Description |
---|---|---|
key | string | The session storage key. |
- Since
- 1.0.0
- Source
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:
Name | Type | Description |
---|---|---|
key | string | The session storage key. |
value | string | The session storage value. |
- Since
- 1.0.0
- Source
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:
Name | Type | Description |
---|---|---|
key | string | The session storage key. |
- Since
- 1.0.0
- Source
Returns:
- Type:
- void
Example
import { sessionStorage } from "@gravityforms/utils";
function Example() {
sessionStorage.remove( 'my-key' );
};