4 ms·
> Things like the `useEffect` dependency arrays and the general naming of hooks seems to lack any thought. In React, everything rerenders newly in response to
by schwartzworld 4y ago
> Things like the `useEffect` dependency arrays and the general naming of hooks seems to lack any thought.
In React, everything rerenders newly in response to state changes. All functions are called on each render. Side effects need to be limited so that they aren't called on every render. The dependency array is where you say "only perform the side effect in response to changes to these specific values".
The problem is that most people aren't used to React's functionalish programming model. It's really common to have way too much state in a React app, and then rely on useEffect to manage that state. If your useEffect isn't reaching outside your React app in some way, it probably represents a flaw in the way you've structured everything.
- aosaigh 4y agoI understand this now, but it took an awful lot of effort to just understand why things are designed like this. I don't think React does a good enough job describing its worldview and why things are they way they are. I actually think that this is another place where its popularity gets in the way: there are so many low quality blog posts clogging up the search results, making it difficult to find any wisdom on the subject.
- schwartzworld 4y agoCheck out the "beta" docs which are far superior https://beta.reactjs.org/learn/synchronizing-with-effects https://beta.reactjs.org/learn/synchronizing-with-effects