Hacker News new | past | comments | ask | show | jobs | submit login

Can you explain why it isn't? I'm probably misunderstanding something.

setText doesn't change because it's from useState. The only reason to update the Dom is because the onclick function isn't memoized.

Updating the Dom every render isn't terrible but it isn't good.




button is just a small lightweight element usually with a single string child. If passing a lightweight unwrapped click handler to a leaf node is a faux pas then honestly the react team needs to memoize by default. Your description "updating the dom every render..." And acting like indiscriminate useCallback is a panacea for your performance problems to me seems like a pretty naive take. But then again seems like the community opinion in this has shifted, I just honestly don't get it. And I do use useCallback btw, but only when I need to keep referential stability for known reasons,not as an automatic default




Consider applying for YC's W25 batch! Applications are open till Nov 12.

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

Search: