React native 重渲染平面列表的问题

React native 重渲染平面列表的问题,react-native,react-native-flatlist,mobx-react,React Native,React Native Flatlist,Mobx React,在删除给定用户时,我正在努力更新列表。大多数问题都是由于我将函数作为setParams放在componentDidMount中,从而丢失了状态 这是_deleteUsers的函数,它删除精细但不更新: _deleteUser(){ var user = firebase.auth().currentUser; var position; _.map(this.selectedMembers, item => { var ref = firebase.

在删除给定用户时,我正在努力更新列表。大多数问题都是由于我将函数作为setParams放在componentDidMount中,从而丢失了状态

这是_deleteUsers的函数,它删除精细但不更新:

_deleteUser(){
    var user = firebase.auth().currentUser;
    var position;
    _.map(this.selectedMembers, item => {
        var ref = firebase.database().ref('path')
        ref.orderByChild('key').equalTo(item.key).on("value", function(snapshot){
            snapshot.forEach(function(child) {
                position = child.key
            });
        });
        delete this.students.members[position]
    });

    firebase.database().ref().child('path').remove(); 

    Toast.show({
        text: "Members deleted successfully!",
        type: "success",
        fontStyle: "italic", 
    })        
}
所有这些都应该在下面的平面列表中呈现

我应该怎么做?我有很多其他的操作,但唯一不起作用的是这个,因为我在componentDidMount中处理它的方式,或者至少,我认为这是我不知道如何解决的问题


谢谢,

传递回调时,您正在丢失上下文。用arrow函数包装回调函数,您将保留原始上下文

更改:

componentDidMount() {
    ...
    this.props.navigation.setParams({ removeUser: this._deleteUser});
    ...
}
为此:

componentDidMount() {
    ...
    this.props.navigation.setParams({ removeUser: () => this._deleteUser()});
    ...
}
constructor(props) {
   super(props)
   this.state = {
            dataSource : [],
            text : '',
            itemNumber : 0,
            selectedItems: [],           
            groupName: '',
            selectedMembers: [],
        }
    }  
    state = {
        refreshing: false,
    }
    refreshList = () => {
        this.state.refreshing = true;
        this.props.navigation.state.params.store = new StudentsStore();
        this.state.refreshing = false;
    }
componentDidMount() {
    ...
    this.props.navigation.setParams({ removeUser: this._deleteUser});
    ...
}
componentDidMount() {
    ...
    this.props.navigation.setParams({ removeUser: () => this._deleteUser()});
    ...
}