wix-storage

wix-storage

Provides functionality for the persistent storage of data items even if the user is browsing other web pages.

You can use wix-storage functions to store data items and retrieve them later even if the user left your Wix page and then returned.

There are two types of storage that you can use:

  • Session — Data items in session storage are available until the user ends the session by closing the browser tab or window of your Wix page. When the session ends, all the items in session storage are deleted. Reloading the page does not affect items in session storage.
  • Local — Data items in local storage never expire, even if the user closes your Wix page. When the user reopens the page later, the data items can still be retrieved.

Some older browsers may not fully support wix-storage. See Browser compatibility for more information.

Usage

Ly8gVGhpcyBsaW5lIGlzIFJFUVVJUkVEIGFuZCB0eXBpY2FsbHkgcGxhY2VkIGF0IHRoZSAKLy8gIHRvcCBvZiB5b3VyIGNvZGU6CmltcG9ydCB7bG9jYWwsIHNlc3Npb259IGZyb20gJ3dpeC1zdG9yYWdlJzsKCi8vIEFsdGVybmF0aXZlbHksIHlvdSBjYW4gaW1wb3J0IGp1c3QgdGhlIHN0b3JhZ2UgdHlwZSB5b3UgbmVlZDoKaW1wb3J0IGxvY2FsIGZyb20gJ3dpeC1zdG9yYWdlJzsKaW1wb3J0IHNlc3Npb24gZnJvbSAnd2l4LXN0b3JhZ2UnOw==
// This line is REQUIRED and typically placed at the 
//  top of your code:
import {local, session} from 'wix-storage';

// Alternatively, you can import just the storage type you need:
import local from 'wix-storage';
import session from 'wix-storage';

See Also

Mozilla: HTML5 Web Storage API

Contents

clear( ) Deletes all data items from local or session storage.
getItem( ) Gets a data item from local or session storage.
removeItem( ) Deletes a data item from local or session storage.
setItem( ) Stores a data item in local or session storage.
clear( )

clear( )

Deletes all data items from local or session storage.

local.clear();
session.clear();
getItem( )

getItem( )

Gets a data item from local or session storage.

let myLocalItem = local.getItem(key);
let mySessionItem = session.getItem(key);

Parameters

key String The key of the data item you want to retrieve.

Return Value

Object The retrieved data item.
removeItem( )

removeItem( )

Deletes a data item from local or session storage.

local.removeItem(key);
session.removeItem(key);

Parameters

key String The key of the data item you want to delete from storage.
setItem( )

setItem( )

Stores a data item in local or session storage.

local.setItem(key, value);
session.setItem(key, value);

Parameters

key String The key of the data item you want to store.
value Object The data item you want to store.