Re:Thoughts on Svelte
by talkingtab on Monday March 27, 2023 @09:57AM
(#35326732)
But then again, you might need an effect. The behind the scenes (or behind the hooks) complexity that react adds in order to the make DOM thing work then makes it difficult when you do need an effect. Things like WebRTC or sockets or some such. useRef? useState? I have found this to be extremely difficult. If someone knows a good resource for doing things like this in React (and not a one page file, but with multiple components etc) I would appreciate knowing about it.
[ Parent
| on HN ]
I'd say pull that logic out of your components and put it in some central place like an XState machine exposed to your components through Context.
That's the case for useSyncExternalStore.
Re:Thoughts on Svelte
by talkingtab on Tuesday March 28, 2023 @08:19PM
(#35350155)
Thanks! Just what I needed.
On a side note, is there a place that talks about this issue in React and explains why this is needed? There is a hint in the doc. It says "... that hold state outside of React".
Using web sockets, events come in and some (and only some )affect components. When a socket is connected there is an explicit state that changes, but how that gets into React-Land is difficult. The same issue exists with WebRTC. What I don't really get is why useRef, useState and useEffect are so difficult to get right.