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

> hooks are THE mechanism they CHOSE to expose component life cycle

Yes, and component lifecycle itself is an escape-hatch (or airlock, or whatever).

> Function component React would be useless without these hooks; the DOM is an external system!

It is an external system, but most fundamental idea of React is that you don't have to write your own effects or lifecycle logic for updating the DOM (the great majority of the time). That's the whole point. The way React lets you update the DOM without using a side-effects programming model most of the time is the reason people use it. Instead of writing side-effects toward the DOM, you write a unidirectional flow of values derived from other values which bottoms-out in DOM (which React then "affects" for you). Custom effects are (mostly) for the situations where you're updating an external system that isn't the DOM.

The biggest problems in my experience come when effects become a part of the core domain logic. That's where things get really hard to follow, and that's the most important thing to discourage. Effects should be reserved for the boundary between the app and the outside world (minus normal DOM updates).



I agree completely. And that's what I liked about this article: it taught me what effects aren't for. I had been using most of the anti patterns in the article (especially using effects to sync props and state with each other), and it showed me a better way to do all these things.




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

Search: