This is my Api class. I initialize the variable client in init:
export default class Api {
constructor (options = {}) {
this.init()
}
async init () {
this.config = await this.loadConfig()
this.client = this.initClient()
this.client.open()
}
initClient() {
...
}
loadConfig() {
...
}
fetchList() {
console.log(this.client, this.config)
}
}
Neither client nor config are accessible from the fetchList function. But they are initialized and have value when I console log them from the init function.
edit I call fetchList from react useEffect
useEffect(() => {
let api = new Api()
api.fetchTaskList({ type: 'active' })
.then((data) => {
console.log(data)
})
},[])