News for hackers. Stuff that matters.
Re:Common Beginner Mistakes with React by bayesian_horse on Monday March 13, 2023 @04:42AM (#35132831)
Again, no. Functional components are not defined by just their "javascript function" but rather by the contract with the rest of the rendering system.

And that's why the context manipulated by hooks looks like a sideeffect, and it often does describe sideeffects, but it doesn't. That context is both an input and an output, only the rendering logic in React decides what to do with that output. Without the rendering logic deciding to execute those sideeffect, the context isn't actually changed at all. Which is why you usually don't need to care about when or how often the component is executed.

Re:Common Beginner Mistakes with React by branko_d on Monday March 13, 2023 @10:35AM (#35136233)
From https://en.wikipedia.org/wiki/Pure_function: "the function return values are identical for identical arguments".

The whole point of pure function is that the caller can understand its dependencies without looking at its implementation, because all dependencies are listed as parameters.

You can redefine what "pure" means if you wish, but that pretty much defeats the purpose.