3 ms·
> I guess if you don't pass your dependencies as an array to a function called useEffect, you aren't using hooks. Win! You joke, but yes. Also, you don't have
by recursive 5y ago
> I guess if you don't pass your dependencies as an array to a function called useEffect, you aren't using hooks. Win!
You joke, but yes. Also, you don't have to follow these. https://reactjs.org/docs/hooks-rules.html https://reactjs.org/docs/hooks-rules.html
And you don't have to rely on the diff remembering which state goes to which widget. To its credit, it seems to do it right at least 99% of the time.
I recognize I'm tilting at windmills here. React is a juggernaut, and many people love it. In fact, many people like the exact things that I don't. And that's ok.
- jolux 5y agoYou may not realize it but you're just rewriting hooks here. The example you give is too simple to show the problems with your initial approach. The main one is that if you're not extremely careful about when you're writing and when you're subscribing, you're going to end up with a race condition. Similar problems if you call "subscribe" in the wrong place. This is not a safe solution to the problem, and it does not circumvent the need for rules about usage.
- recursive 5y agoI'm sure there are complexities that I hadn't considered yet, but I don't see how a race condition can be one of them. Outside of workers, there's really no way to simultaneous concurrency in js. Order of dispatch to subscribers seems like it create similar problems, although it would be fully deterministic, rather than a race. Anyway, thanks for your insight.
- jolux 5y ago> Outside of workers, there's really no way to simultaneous concurrency in js. You're largely right but this part is mostly wrong in practice because of async. You can create race-like conditions very easily with promises/async if you're not careful. > Order of dispatch to subscribers seems like it create similar problems, although it would be fully deterministic, rather than a race. Yes, that's closer to what I meant. Not a data race, but you could end up in a loop.