React render() is being called before componentDidMount()

后端 未结 3 1725
面向向阳花
面向向阳花 2020-12-03 01:14

In my componentDidMount() I am making an API call to fetch some data, this call then sets a state object that I use in my render.

componentDidMo         


        
3条回答
  •  广开言路
    2020-12-03 01:48

    Using setState in componentdidmount. This my code:

     async componentDidMount() {
    
        danhSachMon = await this.getDanhSachMon();
        danhSachMon=JSON.parse(danhSachMon);
        this.setState(danhSachMon);
    }
    
    render() {
        return (
            
                
                        
                            {item.title}
                        
                    }
                    keyExtractor={(item, index) => index.toString()}
                />
            
        )
    }
    

提交回复
热议问题