npm install react-pouchdb-changes
import PouchDBChanges from 'react-pouchdb-changes';
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 the change
event is fired from the changes feed.
onComplete: Function
: Optional. Called when the complete
event is fired from the changes feed.
onError: Function
: Optional. Called when the error
event is fired from the changes feed.
onPaused: Function
: Optional. Called when the paused
event is fired from the changes feed.
children: Any
: Optional. The children that will be rendered by this component. The PouchDBChanges
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.
<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>