【发布时间】:2019-08-29 07:09:30
【问题描述】:
我正在使用 PouchDB 将我的远程数据库与我的本地数据库同步,下面的代码放在 componentDidMount 中
const that = this
var localDB = new PouchDB('localdb')
var remoteDB = new PouchDB('http://192.168.1.106:5984/remotedb')
localDB.sync(remoteDB, {
live: true,
retry: true
}).on('change', function (change) {
console.log('test')
that.setState({
items: [this.state.items, ...change.change.docs]
})
})
我不知道为什么它什么都不做
【问题讨论】:
-
将响应数据添加到描述中以便更好地理解。此外,您在 setState 方法中使用 this.state.items,您应该使用上面定义的 that.state.items
标签: javascript reactjs pouchdb