react warning cannot set state when using promises

前端 未结 7 1330
情深已故
情深已故 2020-12-19 13:40

I\'m trying to query the server to get list of nav items so I can build my menu on init. I\'ve so far managed to create a static page with 3 contents on the home page, which

7条回答
  •  无人及你
    2020-12-19 14:25

    You will try this

         fetch(url)
            .then((response) => {
                   let jsonData=response.json();
                   this.setState({data:jsonData})
             })
            .catch((error) => {
                   console.log("error---",error);
             })
    

提交回复
热议问题