I would like to attach a component to a listener or create a custom hook for that listener.
On client side i would do it like this:
useEffect(() => {
const subscription = observable.subscribe({
next(value) {
setValue(value);
}
});
return () => subscription.unsubscribe();
}, [observable])
Attach the listener with useEffect and unsubscribe it in the return function. But useEffect does not work on server side.
I think this problem can be solved (or has to be solved) on a higher level. If i wait until everything is finished and then run the renderToString function on the server, everything should be up to date. This means:
Afterwards on the client side, where async code can happen and has to be handled, the useEffect hooks will do their job.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.