setState inside Promise in React

后端 未结 3 1636
旧时难觅i
旧时难觅i 2021-01-12 21:47

I have a function in my React code defined like this:

getAttachment(url) {
    fetch(url).then((responseText) => {

        var response = responseText.js         


        
3条回答
  •  滥情空心
    2021-01-12 22:31

    Instead of binding this you could just scope the reference to this. like

    var that = this;
    

    and then reference that.setState.

提交回复
热议问题