News for hackers. Stuff that matters.
Re:React is becoming a black box by eric_b on Thursday September 03, 2020 @09:15AM (#24363702)
React was always a black box, more or less. To me, what happened was the React team decided boilerplate was worse than cognitive load and the appearance of simplicity, and changed the framework accordingly.

Class components are easy to understand and reason about (mostly) - but they result in a lot of boilerplate code for simple functionality and event handling. Hooks, to me, are the opposite. They have all kinds of limitations and footguns which you need to be aware of (yes linters help) but they give the code a much cleaner appearance.

I personally prefer obvious boilerplate over clean aesthetics but I know lots of people who prefer hooks. I've sinced moved to Preact and have not missed real React once.

Re:React is becoming a black box by ng12 on Thursday September 03, 2020 @12:33PM (#24365761)
I'm not sure if I would describe it as boilerplate because it includes very real cognitive overhead. The best example is the lifecycle methods: if you access a prop in componentDidMount you need to remember to handle what happens if that prop changes in componentDidUpdate. It was incredibly easy to write broken components using the class API and much harder with the hook API.
Re:React is becoming a black box by sktguha on Thursday September 03, 2020 @03:30PM (#24367810)
couldn't you just write the same function to handle the prop in both componentDidMount and componentDidUpdate ?
Re:React is becoming a black box by ng12 on Thursday September 03, 2020 @05:55PM (#24369326)
Sure, but you still have to know to do that and to do it correctly by checking whether the relevant values have changed in componentDidUpdate.