使用监听器从领域更新状态不起作用

时间:2019-06-08 09:37:32

标签: react-native realm

我尝试使用'change'侦听器和reloadData函数更新BillList的状态,但是我的尝试不好

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: [] });
        });
    }

0 个答案:

没有答案