News for hackers. Stuff that matters.
Re:React: You Might Not Need an Effect by Rapzid on Thursday March 23, 2023 @06:52AM (#35272736)
> but that it always points to the data closed over by the latest render

It's my understanding that this was to be the behavior of the canceled useEvent hooks but that the new useEffectEvent hook does not return a stable reference.

Do you have sources for the behavior of the new hook?

Re:React: You Might Not Need an Effect by andrewingram on Thursday March 23, 2023 @07:11AM (#35272914)
https://react.dev/learn/separating-events-from-effects#decla...

> Here, onConnected is called an Effect Event. It’s a part of your Effect logic, but it behaves a lot more like an event handler. The logic inside it is not reactive, and it always “sees” the latest values of your props and state.

Re:React: You Might Not Need an Effect by Rapzid on Thursday March 23, 2023 @07:21AM (#35272990)
A bare closure would always see the latest values because it closes over them during render. And the latest useEffect closure will have closed over that method..

Here is the test suite for useEffectEvent and the test ensuring it does not provide a stable reference: https://github.com/facebook/react/blob/main/packages/react-r...

Re:React: You Might Not Need an Effect by andrewingram on Thursday March 23, 2023 @08:12AM (#35273483)
You're right, i'll redact/edit. Hm, this doc page is exceptionally confusing.