Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Proxy to Array in mobx-react

I have an observable variable defined in the store, and I attempt to make multiple calls and push results to the Array. When I am so doing this, I find the array I defined is a proxy so that I cannot display the info in my page.
This is my attempt:

class ClubListStore {
  @observable userClubList

  constructor() {
    this.userClubList = []
  }


  @action getUserClubs = () => {
    const userContract = new appchain.base.Contract(playerAbi, config.userContract)
    appchain.base.getDefaultAccount().then(sender => {
      userContract.methods.getUserClubsSize(sender).call().then((res) => {
        return res
      }).then((res) => {
          for (let i = 0; i < res; i++) {
            userContract.methods.getUserClubs(sender, i).call().then((clubAddr) => {
              this.userClubList.push(clubAddr)//push value to array here
            })
          }
        }
      })
    })
  }


}

const clubListStore = new ClubListStore()

export default clubListStore

When I console.log the array userClubList, it is displayed as a proxy.

Proxy {0: "0xf3fA7DB0Cb79b12ca2081F9f5865f3fd01127FAd", length: 1, Symbol(mobx administration): ObservableArrayAdministration}
[[Handler]]
:
Object
[[Target]]
:
Array(1)
[[IsRevoked]]
:
false

My question is:
How can I convert this proxy to the array that holds values I pushed in from calls?

thank you

like image 364
Frankie Avatar asked Aug 10 '26 13:08

Frankie


1 Answers

use console.log(toJS(userClubList))

https://mobx.js.org/api.html#tojs

like image 156
Thomas Ribeiro Avatar answered Aug 12 '26 19:08

Thomas Ribeiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!