DEV Community

Discussion on: My Experience With React

Collapse
 
peerreynders profile image
peerreynders • Edited

fetching info from API's with useEffect

Thanks to React 18 strict mode useEffect() had a bit of a drama last week—which coincided with

Where 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:

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).