News for hackers. Stuff that matters.
Re:React is becoming a black box by j-krieger on Thursday September 03, 2020 @09:34AM (#24363865)
Yes! A hook call occurs at most once per render. For react to figure out which hook call corresponds to what state, it analyzes the call order. Because we write component render functions top down, the hook call order stays the same every time every render. Not so if we call a hook inside a loop [1].

Why would you call a hook inside a loop anyway? Hooks return callbacks and variables, which you can use inside a loop without problem.

[1]: https://reactjs.org/docs/hooks-rules.html#explanation

Re:React is becoming a black box by beirut_bootleg on Thursday September 03, 2020 @06:19PM (#24369535)
Just as you don't call this.componentDidUpdate in a loop. I'm reading through the comments and trying to figure out what mental model some have of React that causes them to just don't "get" hooks. I'm starting to think this difference in thinking did not start with hooks.
Re:React is becoming a black box by tuesdayrain on Friday September 04, 2020 @11:23PM (#24381184)
Hooks aren't always comparable to lifecycle methods. At my company every GraphQL query/mutation has a corresponding hook. There are frequently times when devs are tempted to use them, especially the mutations, in for loops.