We’ve posted an RFC for useEvent. We suspect it might have been the missing piece in the original Hooks release. It lets you define an event handler that “sees” fresh props/state but has a stable identity. Would love to hear feedback! github.com/reactjs/rfcs/p…
"In React, side effects usually belong inside event handlers. Event handlers are functions that React runs when you perform some action—for example, when you click a button. Even though event handlers are defined inside your component, they don’t run during rendering! So event handlers don’t need to be pure."
David Khourshid's endorsement of useSyncExternalStore() is an assertion that components should not fetch data directly—they should merely "tell" something on the other side of Context that a fetch may be necessary. That something would then later notify any subscribed components to synchronize themselves with the freshly fetched data once it arrives.
@tlakomy i went through 100+ examples at some point in the fb codebase, and about 30% of useEffect calls i’ve seen were unnecessary and/or wrong ways to approach a problem. this is partly an educational issue (we need to explain when not to use it) and partly the api being too generic.
01:48 AM - 10 Mar 2022
PS:
seems to add another layer of understanding to web development and just how far you can take it.
In my opinion React development creates apps that "tunnel" over the web/browser.
"Facebook’s famous React library, the present-day darling of web-dev, uses HTML and javascript but abstracts the [browser itself away]. ... Facebook realizes they have no advantage in the Web over any usurper platform, and helping the Web only further enshrines their competitors. ... In a similar way as React can abstract the HTML DOM away, Facebook has abstracted HTTP away from their service stack. ... Facebook increasingly has no dependence on Web technology." Ref
Web development is more concerned with developing solutions that acknowledge and deal with the web's physical constraints (which is hopefully what Generation 3 is all about).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks to React 18 strict mode
useEffect()
had a bit of a drama last week—which coincided withWhere you can cause side effects
"In React, side effects usually belong inside event handlers. Event handlers are functions that React runs when you perform some action—for example, when you click a button. Even though event handlers are defined inside your component, they don’t run during rendering! So event handlers don’t need to be pure."
David Khourshid's endorsement of
useSyncExternalStore()
is an assertion that components should not fetch data directly—they should merely "tell" something on the other side of Context that a fetch may be necessary. That something would then later notify any subscribed components to synchronize themselves with the freshly fetched data once it arrives.He's had this position for quite some time:
PS:
In my opinion React development creates apps that "tunnel" over the web/browser.
"Facebook’s famous React library, the present-day darling of web-dev, uses HTML and javascript but abstracts the [browser itself away]. ... Facebook realizes they have no advantage in the Web over any usurper platform, and helping the Web only further enshrines their competitors. ... In a similar way as React can abstract the HTML DOM away, Facebook has abstracted HTTP away from their service stack. ... Facebook increasingly has no dependence on Web technology." Ref
Web development is more concerned with developing solutions that acknowledge and deal with the web's physical constraints (which is hopefully what Generation 3 is all about).