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