3 ms·
I've worked with frameworks all over the map in terms of dependency tracking, and right now I'd lean toward React's manual dependency tracking is probably the b
by WorldMaker 7y ago
I've worked with frameworks all over the map in terms of dependency tracking, and right now I'd lean toward React's manual dependency tracking is probably the better approach as the default. Making it manual does mean that it is easy for silly mistakes to be made (missing a dependency or adding one too many), but it's a learning/debugging trick and eventually starts to become second nature. Tools can be built on top of this manual tracking to better automate it, such as edit/compile/pack time linters ("warn: you use this variable in this callback but don't include it as a dependency"), or additional meta-hook libraries at runtime that do some of the automatic dependency tracking magic (through Proxy objects or what have you).
It's harder to fix some classes of mistakes/performance issues in the more automatic systems, and the classes of mistakes in the manual dependency tracking world are often easier to spot ("why isn't this updating?" when forgetting a dependency as opposed to "why is this updating too often?" with automatic tracking).
I wouldn't be surprised if there aren't more automatic tracking tools that show up built on top of the basic hook pattern.
My biggest complaint with the React dependency tracking is that empty dependency array [] has different behavior from null/undefined dependency array and so far I always have to look up which one I actually need and I just haven't yet written enough hooks that I've internalized why which behavior is which. It keeps the hook functions terse to write, but it's a small papercut.
- ratww 7y ago> My biggest complaint with the React dependency tracking is that empty dependency array [] has different behavior from null/undefined dependency array and so far I always have to look up which one I actually need I wish they had used a constant, like "React.everytime" instead of null. I rarely want an useEffect to fire on every render, but wanting it to fire on mount is very popular, to the point a lot of people have an `useMount` custom hook...