This is more a react question I think;
export function useData() {
const [Data]: any = useContractCall({
abi: myContractInterface,
address: myContractAddress,
method: "getAllData",
args: [],
}) ?? [];
return Data;
}
let myData = useData();
<div>{myData ? myData.name : "no Data yet"}</div>
UseData() is called and the view is rendered when myData is propagated; but how could I use myData somewhere else in my logic? Tried with an async wrapper and await, didn't work.
I tried to use useEffect to listen on changes of myData and react, but useEffect is fired immediately and myData is null.
let myData = useData();
useEffect(() => {
console.log("Fresh Data is here",myData);//rotten undefined, not fresh data
}, [myData ])
Should I just use something like this? I mean it is working.. but
const x = useData();
(async() => {
console.log("waiting for variable");
while(!x) // define the condition as you like
await new Promise(resolve => setTimeout(resolve, 1000));
console.log("variable is defined",x);
})();