JSFiddle - React, Tailwind, and code Playground
JavaScript
class Test {
#text;
#timerId;
set text(text) {
this.#text = text;
}
checkText = () => {
let value = this.#text;
console.log("checkText");
if (value) {
clearInterval(this.#timerId);
resolve(value);
}
else {
console.log("checkText")
}
}
get text() {
let value = (async () => await new Promise((resolve, reject) => {
this.#timerId = setInterval(this.checkText, 1000);
}))();
return value;
}
constructor() {
fetch("https://jsonplaceholder.typicode.com/posts/1")
.then((response) => {
response.text().then((response) => {
this.text = response;
// console.log(this.text);
});
});
}
}
let test = new Test();
console.log(test.text);