CorvidReference

Storage

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

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

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

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

   // Or one of:

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

Table of Contents

FUNCTIONS

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

Related Content

FAQ

    What's the difference between local, session, and memory storage?
    Is wix-storage data shared between site visitors?
    What kind of data can I store using wix-storage?

clear( )

Removes all items from local, session, or memory 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();

Remove all items from memory storage

import {memory} from 'wix-storage';

// ...

memory.clear();

getItem( )

Gets an item from local, session, or memory 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"

Retrieve an item from memory storage

import {memory} from 'wix-storage';

// ...

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

removeItem( )

Removes an item from local, session, or memory 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");

Remove an item from memory storage

import {memory} from 'wix-storage';

// ...

memory.removeItem("key");

setItem( )

Stores an item in local, session, or memory storage.

Note

You can store up to 50kb of data in local and session storage and up to 1mb in memory 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");

Store an item in memory storage

import {memory} from 'wix-storage';

// ...

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