I try to update the array of the state when the database is changing, but It not work in real time. I see the update when I re-open the app


#1

I export from the schemas new Realm(databaseOptions)
databaseOption is an object with the schema array

export default class BillList extends React.Component {
constructor(props) {
super(props)
this.state = {
bills: []
}
this.reloadData()
realm.addListener(‘change’,() => this.reloadData())
}

reloadData = () => {
    queryAllBills().then(bills => {
        this.setState({ bills });
    }).catch(error => {
        this.setState({ bills: [] });
    });
}

#2

What does queryAllBills do? Have you reviewed the notifications section of the documentation?


#3

yes. I read the docs. queryAllBills return all objects of type bill from the database


#4

Sure, but why is it a promise? The Realm API are synchronous, so it’s not clear to me what else is happening there for it to become a promise. If you can create a simple app that reproduces the behavior you’re seeing, that will probably help us resolve this quicker.