react-pouchdb-changes
v0.1.1
Published
React component middleware for listening to the changes feed from CouchDB or PouchDB
Downloads
11
Maintainers
Readme
<PouchDBChanges />
Install
npm install react-pouchdb-changes
Using the Component
import PouchDBChanges from 'react-pouchdb-changes';
API
dbUrl: String
: Required. The URL of the remote CouchDB or the name of the local PouchDB to listen to changes from.dbOpts: Object
: Optional. The options that will be passed when connecting to the remote DB. Defaults to an empty object. See the PouchDB Docs for more details.changesOpts: Object
: Optional. The options that determine how to consume the changes feed. Defaults to an empty object. Note that if{live: true}
is passed here the changes feed is continuously polled until the changes feed is canceled or the component unmounts; otherwise the operation is atomic. See the PouchDB Docs for more details.onChange: Function
: Optional. Called when thechange
event is fired from the changes feed.onComplete: Function
: Optional. Called when thecomplete
event is fired from the changes feed.onError: Function
: Optional. Called when theerror
event is fired from the changes feed.onPaused: Function
: Optional. Called when thepaused
event is fired from the changes feed.children: Any
: Optional. The children that will be rendered by this component. ThePouchDBChanges
component does not take responsibility for rendering any UI, so it can be plugged in at the root of your application or anywhere it makes sense to have access to the changes feed.
Example
<PouchDBChanges
dbUrl='http://localhost:5984/mydb'
changesOpts={{
since: 'now',
live: true,
include_docs: true
}}
onChange={change => this.setState({ latestDoc: change.doc })}
onError={err => this.handleError(err)}
>
<App>
...
</App>
</PouchDBChanges>