Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Hooks are often side effects (but not always) and that sounds like "imperative" programming, but actually the side effect is what is inside the useEffect hook, not so much the hook itself.

The component is still a pure function. It "returns" side effects without executing them, just not as the function return value but through a side channel. But that side channel is sort of a clutch to achieve a pure relation from input to output, just that the output is now a return value from the function plus the sideeffects, which may be executed or not.



"Side effect" in my comment means an unintended side effect from an impure functional component (often a case of missing a useEffect, useMemo, or useCallback).


"Side Effect" in functional programming usually means the function is affecting something other than the output. And calling a hooks really doesn't, they just output the description of such an effect on a side channel.


> usually means the function is affecting something other than the output

That's exactly the point. If you leave an errant function call in a functional component, it's going to affect something other than the output of that component.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: