React native 如何在获取新数据时从api更新数据?

React native 如何在获取新数据时从api更新数据?,react-native,navigation-drawer,React Native,Navigation Drawer,在react native中,我可以在使用react stack navigator获取数据时从api更新屏幕中的数据,但在使用react drawer navigator时,我不能。我已经尝试过多次使用“willFocus”监听器。它不起作用。我怎样才能完成这个过程 catId:null, subCatByCatId:[], loading:false, catTitle:'',

在react native中,我可以在使用react stack navigator获取数据时从api更新屏幕中的数据,但在使用react drawer navigator时,我不能。我已经尝试过多次使用“willFocus”监听器。它不起作用。我怎样才能完成这个过程

            catId:null,
            subCatByCatId:[],
            loading:false,
            catTitle:'',
             cat_list:[]
        }

  async componentDidMount(): void {
this.setState({loading:true});
const {navigation}=this.props;
this.WillFocus=navigation.addListener(
    'willFocus',
    async(payload)=>{
this.setState({
    catId:this.props.navigation.state.params.catId
},async ()=>{
    const {catId}=this.state;
    const uri = "https://bilettm.com/api/v1/category/"+catId+"/events"
const apiCall = await fetch(uri)
    const categories = await apiCall.json();
    this.setState({
        subCatByCatId:categories.sub_cats,
        loading:false,
    })

})

    }

);



  }

  componentWillUnmount(): void {
        this.WillFocus.remove();

  }

你能添加一些细节吗,代码?