A set of React hooks and utilities for building real-time, offline-first, and optionally end-to-end encrypted applications using Vaultrice NonLocalStorage.
Under the hood, @vaultrice/react uses @vaultrice/sdk for all storage, sync, and presence features.
Vaultrice is ideal for collaborative apps, cross-device sync, and privacy-sensitive use cases—without custom backend infrastructure.
npm install @vaultrice/react
import { useNonLocalState } from '@vaultrice/react'
const [value, setValue, error] = useNonLocalState<string>('myRoom', 'myKey', {
credentials: {
projectId: 'YOUR_PROJECT_ID',
apiKey: 'YOUR_API_KEY',
apiSecret: 'YOUR_API_SECRET'
}
})
// Use value in your UI, update with setValue(newValue)
useNonLocalState
– Manage a single value with real-time sync.useMultiNonLocalStates
– Manage multiple keys atomically.useNonLocalCounter
– Atomic increment/decrement for counters.useMessaging
– Real-time messaging and presence.createNonLocalStore
– Simple fetch/post API for a single key, eg. to be used with tanstack query / mutation.import { useNonLocalCounter } from '@vaultrice/react'
const [count, increment, decrement, error] = useNonLocalCounter('roomId', 'counterKey', { credentials: { ... } })
<button onClick={() => increment()}>+1</button>
<button onClick={() => decrement()}>-1</button>
<p>Current count: {count}</p>
You can initialize your credentials in a single place to be reused:
// eg. in your index.ts
import { vaultrice } from '@vaultrice/react'
vaultrice.init(credentials)
// in your components
import { useNonLocalState } from '@vaultrice/react'
const [value, setValue] = useNonLocalState<string>('objectId', 'myKey'}
To take advantage of the offline-capable NonLocalStorage you will have to prepare the instances before usage, like:
// eg. in your index.ts
import { prepareOfflineNonLocalStorage } from '@vaultrice/react'
prepareOfflineNonLocalStorage('objectId', credentials)
// in your components it will pick up the prepared offline variant
import { useNonLocalState } from '@vaultrice/react'
const [value, setValue] = useNonLocalState<string>('objectId', 'myKey'}
Have questions, ideas or feedback? Open an issue or email us at support@vaultrice.com
Made with ❤️ for developers who need real-time storage, without the backend hassle.
Try Vaultrice for free!