MCPcopy Index your code
hub / github.com/Terreii/use-pouchdb

github.com/Terreii/use-pouchdb @v2.0.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.3 ↗ · + Follow
75 symbols 186 edges 28 files 8 documented · 11% updated 7mo agov2.0.2 · 2025-09-16★ 756 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

usePouchDB

semantic-release Known Vulnerabilities npm

React Hooks for PouchDB.

Overview

usePouchDB is a collection of React Hooks to access data in a PouchDB database from React components.

The goal of usePouchDB is to ease the use of PouchDB with React. Enabling developers to create offline first apps.

Quick-start

You can find the Getting Started docs here (or on GitHub).

These docs walk you through setting up PouchDB and usePouchDB. They give you also a quick introduction to PouchDB and Apache CouchDB. But PouchDB's Guides are recommended to learn PouchDB.

You can find a introduction to React here.

If you know what you're doing and only want to quick start, read on...

Installation

usePouchDB requires React 16.8.3 or later.

npm install use-pouchdb
# or
yarn add use-pouchdb

You'll also need to install PouchDB. There is also a special browser version:

npm install pouchdb-browser
# or
yarn add pouchdb-browser

To use the useView hook pouchdb-mapreduce must be installed and setup. If you use the pouchdb or pouchdb-browser packages, it is already setup.

npm install pouchdb-mapreduce
# or
yarn add pouchdb-mapreduce

For using the useFind hook pouchdb-find must be installed and setup.

npm install pouchdb-find
# or
yarn add pouchdb-find

Bind usePouchDB

usePouchDB exports a <Provider /> to make one or multiple PouchDB databases available to its components sub-tree.

import React from 'react'
import ReactDOM from 'react-dom'
import PouchDB from 'pouchdb-browser'

import { Provider } from 'use-pouchdb'

import App from './App'

const db = new PouchDB('local')

ReactDOM.render(
  <Provider pouchdb={db}>
    <App />
  </Provider>,
  document.getElementById('root')
)

Hooks

All hooks are listed here.

  • usePouch - Access the database provided by <Provider />.
  • useDoc - Access a single document and subscribe to its changes. The hook version of db.get.
  • useAllDocs - Load multiple documents and subscribe to their changes. Or a range of docs by their ids. The hook version of db.allDocs.
  • useFind - Access a mango index and subscribe to it. Optionally create the index, if it doesn't exist. The hook version of db.createIndex and db.find combined.
  • useView - Access a view and subscribe to its changes. The hook version of db.query.

Example

Load a single document and display it. useDoc is the hook version of db.get, but it also subscribes to updates of that document and automatically loads the new version.

import React from 'react'
import { useDoc } from 'use-pouchdb'

export default function Post({ postId }) {
  const { doc, loading, error } = useDoc(postId)

  if (error && !loading) {
    return 

something went wrong: {error.name}


  }

  if (doc == null && loading) {
    return null
  }

  return (
    <article>



        <h3>{doc.author}</h3>


{doc.text}





    </article>
  )
}

Changelog

usePouchDB follows semantic versioning. To see a changelog with all usePouchDB releases, check out the Github releases page.

Contributing

Contributions in all forms are welcomed. ♡

If you have questions, Contributing.md might answer your questions.

To create a welcoming project to all, this project uses and enforces a Code of Conduct.

Extension points exported contracts — how you extend this code

FindHookOptions (Interface)
(no doc)
src/useFind.ts
State (Interface)
(no doc)
src/state-machine.ts
PouchContextObject (Interface)
(no doc)
src/context.tsx
Options (Interface)
(no doc)
src/test-utils.tsx
CommonOptions (Interface)
(no doc)
src/utils.ts
DocsSubscription (Interface)
(no doc)
src/subscription.ts
ExplainResult (Interface)
(no doc)
src/useFind.ts
StartLoading (Interface)
(no doc)
src/state-machine.ts

Core symbols most depended-on inside this repo

waitForNextUpdate
called by 266
src/test-utils.tsx
renderHook
called by 146
src/test-utils.tsx
useView
called by 72
src/useView.ts
waitForLoadingChange
called by 52
src/test-utils.tsx
useFind
called by 30
src/useFind.ts
useDoc
called by 21
src/useDoc.ts
useAllDocs
called by 19
src/useAllDocs.ts
sleep
called by 17
src/test-utils.tsx

Shape

Function 43
Interface 14
Method 11
Class 7

Languages

TypeScript100%

Modules by API surface

website/pages/en/index.js12 symbols
src/subscription.ts11 symbols
src/useFind.ts8 symbols
src/test-utils.tsx7 symbols
src/state-machine.ts6 symbols
src/context.tsx6 symbols
src/useView.ts5 symbols
src/subscription.test.ts4 symbols
website/core/Footer.js3 symbols
src/useAllDocs.ts3 symbols
src/utils.ts2 symbols
src/useView.test.ts2 symbols

For agents

$ claude mcp add use-pouchdb \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact