Socket
Book a DemoInstallSign in
Socket

@containrz/container-indexeddb

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@containrz/container-indexeddb

## Persist your data

latest
Source
npmnpm
Version
0.2.7
Version published
Maintainers
1
Created
Source

@containrz/container-indexeddb

Persist your data

If you'd like to have a persistent state in indexeddb, you can do so by having your container extend IndexedDBContainer.

The implementation is the same as using the Container from @containrz/core.

import { IndexedDBContainer } from '@containrz/container-indexeddb'

interface User {
  name: string
  email: string
  phoneNumber: string
}

export class UserContainer extends IndexedDBContainer<User> {
  state = {
    name: '',
    email: '',
    phoneNumber: '',
  }

  public setUser = (user: User) => this.setState(user)

  public setName = (name) => this.setState({ name })

  public setEmail = (email) => this.setState({ email })

  // ...
}

Cleanup remark

Anytime that you use clearContainers from @containrz/core, the databases created will be all cleared, and the data will, obviously, no longer persist.

If, however, you'd like to manually trigger a deletion of the database for any given container, you can call the clearDB method:

export class UserContainer extends IndexedDBContainer<User> {
  // ...

  public cleanup = () => this.clearDB()

  // ...
}

Other ways to store your state

containrz also allows you to use different base Containers to store your states in other ways. Read more about it in the subprojects:

FAQs

Package last updated on 17 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts