CodeAPI

Storage

Used for storing local or session key/value data in the user's browser.

To learn more about local and session storage, see wix-storage.

To use the Storage API, import the needed storage type(s) from the wix-storage module:

   import {local, session} from 'wix-storage';

   // Or one of:

   import {local} from 'wix-storage';
   import {session} from 'wix-storage';

Table of Contents

FUNCTIONS

?
Perform actions on an object.
clear( )Removes all items from local or session storage.
getItem( )Gets an item from local or session storage.
removeItem( )Removes an item from local or session storage.
setItem( )Stores an item in local or session storage.

clear( )

Removes all items from local or session storage.

See Also

remove( )

Syntax

function clear(): void

Examples

Remove all items from local storage

import {local} from 'wix-storage';

// ...

local.clear();

Remove all items from session storage

import {session} from 'wix-storage';

// ...

session.clear();

getItem( )

Gets an item from local or session storage.

See Also

setItem( )

Syntax

function getItem(key: string): string
PARAMETERS
?
Values that you pass to a function.
key
string
The key of the item to get.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
string
The retrieved item value.

Examples

Retrieve an item from local storage

import {local} from 'wix-storage';

// ...

let value = local.getItem("key"); // "value"

Retrieve an item from session storage

import {session} from 'wix-storage';

// ...

let value = session.getItem("key"); // "value"

removeItem( )

Removes an item from local or session storage.

See Also

clear( )

Syntax

function removeItem(key: string): void
PARAMETERS
?
Values that you pass to a function.
key
string
The key of the item to remove.

Examples

Remove an item from local storage

import {local} from 'wix-storage';

// ...

local.removeItem("key");

Remove an item from session storage

import {session} from 'wix-storage';

// ...

session.removeItem("key");

setItem( )

Stores an item in local or session storage.

See Also

getItem( )

Syntax

function setItem(key: string, value: string): void
PARAMETERS
?
Values that you pass to a function.
key
string
The key of item to set.
value
string
The value of the item to set.

Examples

Store an item in local storage

import {local} from 'wix-storage';

// ...

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

Store an item in session storage

import {session} from 'wix-storage';

// ...

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