I recently started an App in ReactJs and there are some areas where I still lack some knowledge, so my question may be a bit basic. Analyzing the following code:
updateContent(mainUrl){
console.log("updateContent was called")
fetch(mainUrl)
.then((responseJsonAnyUrl) => responseJsonAnyUrl.json())
.then((responseJsonAnyUrl) => {
this.setState({
mainUrl: mainUrl,
jsonObject: responseJsonAnyUrl
},
function testName() {
let interval = 20000
let ind = this.child.current.getCurrentIndex()
let zlengths = this.child.current.getZoneLengths()
let option = 1
if (ind !== zlengths[0]-1){
//didn't iterate trough all content, can't update
option=2
interval = 5000
}
console.log('ind', ind)
console.log('len', zlengths[0]-1)
console.log('interval', interval)
this.timeout = setTimeout(
function(){
if (option===1){
this.updateContent(mainUrl)
}else if (option===2){
// call testName()
}
}.bind(this, mainUrl)
,
interval)
}.bind(this))
})
}
I have a " self-invoked function()
" which I gave the temporary name: " testName
".
In the 2nd comment, I want to be able to call testName()
again, but I could not find the right syntax to do it. How can I call it correctly?
Note: I leave the link for the class / component where this method is found, in the case of be useful.