|
|
|
|
|
by wryanzimmerman
1058 days ago
|
|
Almost all of the issues you’re pointing out come from misunderstandings about derived state and side effects. Derived state should be eliminated! If it can be derived, it’s not state. If you aren’t trying to do derived state patterns, you don’t need to access the previous value. That’s a huge red flag. Likewise, “state” in useRef is a huge red flag. useMemo() is often a signpost pointing to bugs. If the useMemo cannot be removed without getting a different behavior in the application, that’s wrong—it might be slower, but the result should be the same with or without it. It’s not a side effect free rendering model. Mouse interactions, requests, etc, are side effects; the pattern is side effect sets state and state defines the render. The problem happens when people try to “outsmart” this pattern and try to jump from side effect to outcome by subverting the state pattern, which makes them lose most of the advantages of react. Any discussions around “triggering renders” or “preventing renders” before the component is behaving correctly are also big time red flags. |
|