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

It would be amazing if JS could have object equality in a performant way. I'm not sure if Python does anything interesting under-the-hood, but identical Python dicts have deep equality just fine. That would make hooks great in my opinion, where as right now they are just good. Dealing with object non-equality is like 90% of the friction I experience with hooks. Any pattern that requires me to reorganize my code (e.g. passing in individual parts of an object rather than just the whole object to the dep array) is an inelegant pattern, imo.


This.

The article would be completely contentless if not for pointing out the genuine pain that is JS object equality (the issue is that this is a JS pain and not a React pain: hooks just makes it more apparent).

The only thing I'll say is that battling with this pain has tended toward my inventing less generalised but more readable/maintainable/elegant solutions to most individual problems where I've encountered it. e.g.:

- object equality would solve this problem easily :(

- maybe I should've enforced strict immutables throughout?

- oh maybe I could approach it differently. Yes, let's try solution X

- hmm solution X isn't very reusable but it sure is clear and intuitive to read


Not sure if it would fit with your use case, but for me, immer.js has been a game changer in terms of object equality/mutability.

https://immerjs.github.io/immer/docs/introduction

Once all state/object changes are being updated this way, a simple === can check for object equality. It's so useful, it makes me wish this was baked into the language itself.




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

Search: