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.

        
            
            Storage.set('date', new Date());
          
        
    

Set the expiration time

You can set the expiration time (in days) of saved data in local storage

        
            
            Storage.set('date', new Date(), 1);
          
        
    

Get storage

If you have saved any data in the storage, you can load them using the Storage.get method.

        
            
            Storage.get('name');
          
        
    

Remove Storage

When the data saved in storage are no longer needed and you want to delete them, use Storage.remove method.

        
            
            Storage.remove('name');
          
        
    

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.

        
            
            Storage.check('name', 0.5, () => {
              // do something
            });
          
        
    

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.

        
            
            <!-- Modal -->
            <div
              class="modal fade"
              id="exampleModal"
              tabindex="-1"
              aria-labelledby="exampleModalLabel"
              aria-hidden="true"
            >
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModal">This is modal for new user</h5>
                    <button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
                  </div>
                  <div class="modal-body">
                    This model will not appear again until you press the reset button.
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">
                      Close
                    </button>
                  </div>
                </div>
              </div>
            </div>
            <!-- Modal -->
          
        
    
        
            
            Storage.showModalNewUser('exampleModal');
          
        
    

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.

        
            
            <!-- Modal -->
            <div
              class="modal fade"
              id="exampleModal"
              tabindex="-1"
              aria-labelledby="exampleModalLabel"
              aria-hidden="true"
            >
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModal">This model shows up after the third visit to the page.</h5>
                    <button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
                  </div>
                  <div class="modal-body">
                    This model will not appear again until you press the reset button.
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">
                      Close
                    </button>
                  </div>
                </div>
              </div>
            </div>
            <!-- Modal -->
          
        
    
        
            
            Storage.showModalScoring('exampleModal', 3);
          
        
    

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';