In react / nextjs can we set State of functional component from inside worker thread. for example
//main.ts
export function myComponent (){
const [user ,setUserDetails] = useState(false)
const [profile ,setProfile] = useState(false)
....
useEffect( () => {
worker = new Worker('my.ts');
worker.postMessage([user,profile,setUserDetails,setProfile])
},[])
}
and then in worker thread
/* my.js* /
self.onmessage = (data)=>{
//long task
users = getUSers();
// this valid?
data.setUserDetails(user);
// continue process
profile = getProfile();
data.setProfile(profile);
//and so on
}
Is this possible as we can't directly update dom in worker but I think react uses virtual dom.So it could still be possible.If not what is work around for this?