Storage management
Bootstrap 5 Storage management plugin
Storage component allows you to manage data stored in the browser's memory. Thanks to the component, you can easily add, delete, get data and check their expiration time.
Storage management in the latest Bootstrap 5. Manage data stored in the browser memory. Thanks to the component, you can add, delete, get data and check their end time.
Note: Read the API tab to find all available options and advanced customization
Basic example
The Storage Component provides methods to add, remove and get Storage.
Set Storage
Use the method Storage.set()
to add data to storage. You can test this method
using the example below. The button will call
Storage.set('date', new Date());
. To use this example again, press the reset
button.
Set the expiration time
You can set the expiration time (in days) of saved data in local storage
Get storage
If you have saved any data in the storage, you can load them using the
Storage.get
method.
Remove Storage
When the data saved in storage are no longer needed and you want to delete them, use
Storage.remove
method.
Check Storage
You can set a task to check if the data has expired, delete it and set callback function.
Set data name
, the interval
(in minutes) on how often to check
expires date, and callback fn
.
Advanced example
Show Modal for new users
Using the showModalNewUser
method you can display the modal for new users.
Click start button to start simulate this behavior. After next click modal don't show any
more until you click reset.
Show modal after next visit
If you want to display the modal to the person who will visit the page again, you can use
the showModalScoring
method. Enter as a parameter the information after how
many visits to the website the modal should appear. Click start button 3 times to test this
feature.
Storage management - API
Usage
Via JavaScript
Storage.set('date', new Date(), 1);
Methods
Name | Description | Example |
---|---|---|
set |
Add new data to local storage |
Storage.set( ... )
|
get |
Get data from local storage |
Storage.get( ... )
|
remove |
Remove data from local storage |
Storage.remove( ... )
|
check |
Check the data has not expired |
Storage.check( ... )
|
Storage.set('name', 'value', 1);
Import
MDB UI KIT also works with module bundlers. Use the following code to import this component:
import Storage from 'mdb-storage';