Readit News logoReadit News
Osmose · 2 years ago
> React was meant to be a way to provide snappy page loads and UX.

This is a very common misconception. React was meant to provide one-way data flow. With an app built directly on the DOM you have to deal with the DOM having its own state to manage on top of the state your own code is storing. You have a list of comments in a variable, and a list of DOM elements for each comment, and nothing but your own code is making sure they stay in sync with each other. React changed things so that the state of the DOM is always derived from your own app's state, which eliminates what turned out to be a pretty tedious and error-prone amount of work in complex web apps.

It wasn't the first to provide this but its API was unique and compelling vs existing alternatives. The virtual DOM, server-side rendering, etc. are not things that make React faster than non-React code, they are things that counteract the inherent slowness in React's design to make it competitive with non-React code.

Watch the original JSConf talk where React was publicly announced and released, and notice how the talk is mostly about the one-way data binding, and the virtual DOM/reconciliation are mentioned in the back half as ways React catches up to non-React app speeds: https://www.youtube.com/watch?v=GW0rj4sNH2w

coldtea · 2 years ago
>This is a very common misconception

Not really a misconception: it was explicitly pushed and advertised as such, most of the advocacy (especially from React fans) at the time React was introduced and started gaining traction was about the virtual DOM being "faster".

>React changed things so that the state of the DOM is always derived from your own app's state, which eliminates what turned out to be a pretty tedious and error-prone amount of work in complex web apps.

I dunno, I used Redux for a few years, and it was a "pretty tedious and error-prone amount of work in complex web apps" too.

elbear · 2 years ago
Controversial opinion: Redux (and the Elm architecture behind it) only works with a typed language like TypeScript (or Elm) which takes away the error-prone part. With good type completion, some of the "pretty tedious" part goes away as well.
jinushaun · 2 years ago
No. My team migrated to react from in 2015 because the biggest selling point was maintainability, not speed. The virtual DOM was originally marketed as why “react is NOT slow”. It was never about pure speed. I think the misconception all came later by other people.
Osmose · 2 years ago
> it was explicitly pushed and advertised as such

I'm sure React fans who misunderstood the virtual DOM (which was explicitly advertised because it was the most popular part of React[1] vs the other parts that people were more critical of) may have said this, but I never saw the project itself advertising itself as faster than vanilla JS, only that it could be faster than competing frameworks, _especially_ ones that rebuilt the DOM unnecessarily.

> I dunno, I used Redux for a few years

Redux is a different library than React. State management across an app is a problem even for non-React applications, it's not like React _uniquely requires_ work to address state management.

I don't see why your dissatisfaction with Redux has anything to do with React making a very specific and buggy part of building web apps easier to manage in return for a performance cost and following its API.

[1]: See mention near the end of https://medium.com/@dan_abramov/youre-missing-the-point-of-r...

troupo · 2 years ago
> at the time React was introduced and started gaining traction was about the virtual DOM being "faster".

At the time it was. Especially compared to how apps were built at the time.

Note that even today virtual DOM libs (not the same implementation as React's) are still among the fastest: https://krausest.github.io/js-framework-benchmark/2024/table...

the_gipsy · 2 years ago
You now had to deal with react instead of the DOM. Mission accomplished.
ZephyrBlu · 2 years ago
> I dunno, I used Redux for a few years, and it was a "pretty tedious and error-prone amount of work in complex web apps" too.

This makes no sense. Redux is extremely simple with a very small API. If the code using it is tedious and error-prone, that's the fault of the people who wrote that code not Redux.

E.g. "everything must be an action and have an associated reducer" is nothing to do with Redux itself.

latchkey · 2 years ago
The one way data binding was also important at the time, for people coming from Angular. It was a way to clearly differentiate the two frameworks.
bell_tower · 2 years ago
Unfortunately people do not find out what it was meant for, before they start writing about it
88913527 · 2 years ago
We're at the point where many newer engineers haven't had real hands-on DOM experience but are expected to deliver applications built in React. You need to know at least one level abstraction below your current one to use the tool effectively. This all tracks with how the industry's changed, how we hire, how we train, and so on.
treflop · 2 years ago
People start using React as part of a larger framework or existing app and they associate all these unrelated things to React.

Also, the poster says this line:

> Finding a dev who actually groks the gap between useEffect and useMemo, error boundaries, hook based fetching or my (un)favourite, authentication, is difficult.

But truthfully the problems those constructs solve are problems in every paradigm. If you can’t grasp the difference these things despite being a heavy user of a library, you may… want to spend some time reading the docs at some point.

coldtea · 2 years ago
Unfortunately all the early was advocacy focused on how the virtual DOM is "faster", so the people are fully excused for not finding out "what it was meant for".

The "UI as a function of state" was not just sold as "more functional/simpler", but also as a necessity to have a DOM diffing algorithm to minimize updates and be "faster".

songbird23 · 2 years ago
I dont use react professionally(vanilla) but its ideas of one way data binding and UI is a function of state have continuously been helpful in building predictable apps that doesnt grow too hairy. an app can still grow in complexity as it becomes bigger but the ideas definitely help
symaxian · 2 years ago
Yeah, I cannot count how many times I've seen it claimed that the virtual DOM is the secret to why React(or another framework) is fast, completely missing the point of the virtual DOM.

The virtual DOM is not faster than performing direct mutations of the actual DOM, the virtual DOM is a tool that allows the normally slow approach of "blow away and rebuild the world" to be fast enough to put into use.

throwaway11460 · 2 years ago
Virtual DOM used to be faster than DOM. DOM operations were really slow back when React came out, and the usual componentization approach of replacing entire blocks of code with new HTML strings used to lock up the browser. React made it possible to effortlessly reuse previous state DOM nodes.
ethanbond · 2 years ago
This was super informative, thanks for writing it up!
dudefeliciano · 2 years ago
don't hooks break the whole concept of one way data binding?
Osmose · 2 years ago
Nope. The binding is "one-way" in the sense that, when the component state (or props) change, the DOM is updated, but if the DOM changes, the component is not updated. Hooks are a pattern for declaring state, side effects, etc. but they don't materially change this relationship.
Gigacore · 2 years ago
> React is the automatic target for a lot of newbies. They jump straight into webdev, learn some HTML/CSS and eventually work their way towards React for employability.

This has been the trend largely for last 3 to 4 years with the candidates (<5 yoe) I have interviewed. I probe them on core fundamentals of Javascript, HTML and CSS. When I get to the nuances, most of them outright call it out saying that they are React developers and do not do Javascript without realizing the fact that React is based on Javascript. And other common misconception is that they assume JSX works the same way while writing the vanilla Javascript code.

cqqxo4zV46cp · 2 years ago
Yup. I’m hiring for a mid-level FE role right now, and the number of “React developers” that don’t know JS fundamentals is incomprehensible. I’m not talking about anything esoteric. Just the sorts of things that I as someone that’s far from a JS expert considers necessary to work in that space day to day. I’m more and more just taking it as a given now that someone won’t have much if any experience writing CSS by hand. If they do, never in an actual .css file. Always via some CSS in JS something or other. A strange new world out there.
ssijak · 2 years ago
Give us some examples of JS fundamentals they do not know
Tade0 · 2 years ago
I've reduced my JS interview test to just one question: "What examples of falsy values can you name?".

Anyone working with the language will be inevitably regularly reminded which these are.

The least mentioned is NaN followed up by... false. But I can't blame anyone for forgetting that one, as it's too obvious.

bryanrasmussen · 2 years ago
about 23-24 years ago me and another senior developer were working on some important parts of the product we were building, and we had a minor task for a company that was paying a little bit, so we handed it over to a guy who was junior but should really have been better (he had the wrong kind of Laziness).

After some hours I saw him walking around with that programmers walk we get when trying to figure out a particularly hard problem. So I went over to check on him.

He informed me that his code to read in the XML file and transform it with the XSLT I had given him worked perfectly in IE but in Netscape there was some sort of problem with the ActiveX control he was using.

So - I figure assuming "JSX works the same way" is the modern day version of that.

at-fates-hands · 2 years ago
Interesting story.

When all the frameworks were taking off, I was at a huge company using a 15 years legacy front-end. My background was "traditional" front-end. HTML/CSS/JS and mostly jQuery at the time.

Every time I went in for an interview, the senior devs would always start with fundamental JS stuff and then go from there. I would consistently get comments about how I was the first person they interviewed who could actually talk to basic JS stuff like closures and scope chain. They said there was a huge influx of people learning React and Angular and had no idea the difference between the two or like you said, they were based on JS.

This was back around 2014/2015 and it looks as though not much has changed since then.

greenie_beans · 2 years ago
was at a bar and i met some guy who was like a year into his first software dev job and somebody was asking us about learning to code and i said to learn html/css first and he was like, "you don't need to know that, just learn react. i don't know anything about html."

i kept my judgement to myself and just ignored his advice. hopefully he's learned html.

claytongulick · 2 years ago
I had a similar experience back in the early 2000's.

I was working with a senior developer who was having trouble moving something up on the the page when something else disappeared. He was using asp.net server controls, it was all he knew.

I suggested "just wrap the content you need to hide in a div and style it with display: none, your content will automatically float up"

He answered me with a sort of superior sneer: "I'm a .net web developer, I don't know what a div is, and I don't intend to learn it".

To be fair, that was a different time and MS was trying hard to make web development act like VB desktop development, but still...

The moment sticks out to me.

MattDaEskimo · 2 years ago
This sounds like the complaints from a new developer that's frustrated over the layers of web dev.

React does a fantastic job working with common developer principles such as Don't Repeat Yourself, and Single Source of Truth.

Their points come across as overly vague and lack any true insights into development besides initial impressions.

For a static page it doesn't make sense to use React, obviously. For a highly interactive page it, or another framework is critical to clean, manageable code.

treve · 2 years ago
Maybe it's a bit vague or don't have 'true insight', but I would still encourage anyone sharing their feelings, even if they're not expert level insights. React applications turning into a maintenance nightmare and the meta changing under your feet is a common sentiment and I think it's helpful if more people talk about this.

One issue in the frontend space is that React has been the default no-questions-asked choice, but my personal vague, no-true-insight feelings are also that you need a technically very proficient team to avoid it turning into a maintenance nightmare.

Many people work for SMBs, and it feels like there's not a great golden path currently for frontend. Doing a something simpler somehow feels like a bigger risk to the people I chat with.

danjac · 2 years ago
I have seen so many React code bases that are the polar opposite to "clean, manageable code" that I would strongly disagree with this premise.

That's not to say React is to blame, per se, but good code is the result of good developer practices rather than some framework.

tauchunfall · 2 years ago
>For a static page it doesn't make sense to use React, obviously

JSX is a nice templating language. And when you use Deno or Bun you can use it directly on server-side. My server-side components have no hooks and use preact-render-to-string or `renderToString()` from `react-dom/server`.

Also there is Gatsby which is a popular content management system which also allow non-interactive statically rendered pages (as far as I remember).

mvdtnz · 2 years ago
JSX is a mediocre templating language that's missing a ton of features from more mature templating languages like Razor
NathanaelRea · 2 years ago
Or Astro, and plugins for React/Tailwindcss/etc. Components are just nice to work with because of their modularity. Using the ergonomics "most web devs" are familiar with is just nice.
benatkin · 2 years ago
> you can use it directly

Because of a poor design choice in an otherwise well designed platform (at least in the case of Deno).

webprofusion · 2 years ago
True, but they're not a new developer, so maybe he's just saying what everyone thinks.
OccamsMirror · 2 years ago
Can confirm the author (not me) has been doing web and system development, including React dev, for over a decade. His complaints are borne of his own frustrations.
mr_toad · 2 years ago
It actually is quite suitable for static pages where the content itself is quite dynamic (e.g. from a CMS or other database), especially when rendering repetitive data structures (e.g. lists of items). You use React on the server to render the contents on the fly as static html and serve that.
brianhama · 2 years ago
What you are describing falls outside the definition of a static page. At least insofar as I’ve always understood.
vjerancrnjak · 2 years ago
A good question is "What is interactive?" Many "interactive" things can be done just with CSS and HTML.

* a list of elements you can select and delete/bulk-edit is feasible with <form>

* any kind of form with input

* hide/show toggle

* tabs

* accordions

Many single page apps aren't really interactive or require minimal JS.

Currently, we're doing things in JS (like forms, pages, tabs, virtualized lists & tree views, hovers, even buttons with JS click handlers) just because our server does not render HTML.

wonnage · 2 years ago
It’s true that a lot of simple apps could just be written using direct DOM manipulation, but you basically write yourself into a corner. There’s no gradual transition from that to any framework, you just have to rewrite your app

Might as well just start with the least common denominator that everyone knows and is easily hired for

greenie_beans · 2 years ago
lots of folks bash react without actually knowing how to use it.
andrewstuart · 2 years ago
I love React but I use no state management, apart from useState locally within components.

State management in React is a major source of pain and complexity and if you build you application using events then you can eliminate state entirely.

Most state management in react is used to fill out props and get the application to behave in a certain way - don't do it - too hard, drop all that.

Here is how to control your React application and make it simple and get rid of all state except useState:

    const ImageComponent = () => {
      const [cacheBust, setCacheBust] = useState(0);

      useEffect(() => {
        const eventListener = () => setCacheBust(Date.now());
        window.addEventListener('customEvent', eventListener);
        return () => window.removeEventListener('customEvent', eventListener);
      }, []);

      return (
        <div>
          <h2>Profile Image</h2>
          <img
            src={`https://example.com/profile-image.jpg?cachebust=${cacheBust}`} // Image URL with cacheBust as query param
            alt="Profile"
            style={{ maxWidth: '200px' }}
          />
        </div>
      );
    };

    // Component that dispatches custom event
    const DispatcherComponent = () => {
      const dispatchCustomEvent = () => window.dispatchEvent(new CustomEvent('customEvent'));

      return (
        <div>
          <h2>Dispatcher Component</h2>
          <button onClick={dispatchCustomEvent}>Reload Image</button>
        </div>
      );
    };
Trust me - once you switch to using custom events you can ditch all that crazy state and crazy usage of props to drive the behaviour of your application.

hermanradtke · 2 years ago
I worked on a system where someone did this. They didn’t consider data races so managing this system became impossible.

I don’t use redux, but I also don’t think this is the way.

andrewstuart · 2 years ago
>> They didn’t consider data races so managing this system became impossible.

What do you mean? I build systems like this all the time and they work fine, no "data races" whatever that means.

emadda · 2 years ago
Why not use a MobX state class, then just write to state.cache_date? The state is in the parent lexical scope of the components, so no prop drilling or providers.

I used to use events just like this, but once the app gets bigger it’s hard to keep track as the event keys are strings. There is no IDE support for tracking usage (functions and class properties allow jumping to and from usage).

Also MobX tracks dependencies based on reads and auto re-renders changed components. This replaces having to hook up event receivers manually to re-render.

I think there are newer mobx state management systems nowadays (Signals is the new term).

maronato · 2 years ago
Events and state need not be mutually exclusive. I like Vue’s approach of state going down the DOM tree and events going up. This works really well with Context and custom events that are dispatched by components (vs by the window as you did).

IMO global events can get messy quickly and make it really hard to develop more complex apps where you have the same component in multiple branches of the DOM firing the same events.

Pufferbo · 2 years ago
This is similar to one method that I’ve used in the past with the BroadcastChannel API. You can essentially create a pub-sub pattern in the frontend. It worked well for microFEs, but now that Preact released their Signals library I’ve moved to that.
the_gipsy · 2 years ago
Building on top components (un)mounting makes your components impure (it called useEffect for a reason). Suddenly you can't trust what you see because THAT might be the edge case. Unit tests don't work either.
stnmtn · 2 years ago
How is this different from the goal of redux or contexts other than ergonomics?
andrewstuart · 2 years ago
I don't see anything in common with Redux or contexts.

No libraries. No higher order components. No concepts to learn. No weird rules. No complex tracing of props and trying to work out why state updates were not triggered, or were triggered.

Redux is one of the most painful software development experiences I have had.

Just the thought of using Redux fills me with dread.

The event code above simply sends a message directly between components - that's nothing at all like Redux.

Can you describe how the above is like Redux?

kamikaz1k · 2 years ago
I just don’t understand why you’d like react if you like working with events. Sounds like you just JSX? Wouldn’t you get better served by something like lit?
andrewstuart · 2 years ago
React is more than JSX.

I think react is great except the concept of using a one way flow of props to drive the application via state is flawed and too complex and hard to debug and has cross cutting issues.

React provides a nice application architecture with minimal usage of props and no global state or contexts.

65 · 2 years ago
Why? Just use Context. It's very simple to understand. Wrap your app in some Context and you can do all that without messing with the window.

Dead Comment

gloosx · 2 years ago
React is actually really simple functional renderer, 20 files, 316 KB

It is not difficult or complex at all to use pure functions and seven hooks. They are documented exceptionally well.

All the complexity author is complaining about he created himself. You can keep the browser router if you want, it can be synced with reactive state using a single side-effect and a single reducer, you don't need to replace it with react-router. You don't need to use Next.js. You don't need SSR or graphql. You can use just regular CSS if you want. This is not complexity that "comes with React", React comes with nothing like that. This is complexity you are stuffing into it.

mvdtnz · 2 years ago
I stopped writing anything in react the moment they introduced that ridiculous hooks API. Very clear they have no clue at all. There are plenty of other options that don't reach so hard to appeal to functional purist propeller-heads.
maronato · 2 years ago
I couldn’t disagree more. Having components be pure functions makes testing and developing so much easier, not to mention the reusability of hooks. Class components were a mess. They had way too much business logic and state stuffed into them that it was impossible to maintain any reasonably large component.

Of course you can still write shitty code with functional components and hooks, but at least now the paradigm itself steers you towards more maintainable code

nitwit005 · 2 years ago
Having uses both, it just feels like trading one set of quirks for another set of quirks.

In general, hooks seem tidier, but the quirks of useEffect seem rather more surprising than the old way.

chrisco255 · 2 years ago
The hooks API is entirely optional. By all means you could continue using Redux or Mobx or class components.
kaba0 · 2 years ago
Sounds like you are the one without any clue, unless you have anything substantial to say.
gustavus · 2 years ago
Cycle of frameworks:

Young dev: it is way too complicated to do something as simple as a todo or hello world app. You have to configure a dozen settings, install 10,000 dependencies and fiddle with too much stuff. I'm going to create a framework that is simple, lightweight and easy to use.

Time passes, framework becomes popular blogs write about how framework X is the future. If you don't have 10 years in framework X you can't get a job. People start using it for things features get added to accommodate needs. People argue saying it's necessary it fits the demand. Framework X becomes a gigantic bloated monstrosity, development slows as useless bureaucratic leeches posing as developers create a "foundation" to "shepherd Framework X towards a bright future." At this point usually the creator leaves or is driven out.

A young developer comes along and says to himself "it is way too complicated to do something as simple as a todo or hello world app. You have to configure a dozen settings, install 10,000 dependencies and fiddle with too much stuff. I'm going to create a framework that is simple, lightweight and easy to use."

The Wheel of Development turns, and frameworks come and pass, leaving defaults that become best practices. Best practices fades to srandards, and even standards is long forgotten when the problem that gave it birth comes again.”

giljabeab · 2 years ago
On the contrary some much older and experienced frameworks are simplifying and consolidating. .NET for example
kevinsync · 2 years ago
lol which of the Forsaken is React? Aginor, creator of the Shadow DOM?
bemusedthrow75 · 2 years ago
This article is written from a lack of experience of fundamentals and it is not very rigorous, but it's kinda sorta not wrong.

I have been thinking for a while about specialising in teaching how the web came to be, so people who are non-technical can understand enough to commission work, understand proposals, etc.; because I think people have no sense of what goes on under the hood.

But increasingly I think it's junior developers and web-oriented designers who need to be taught it.

(Also the developers of Hacker News: "flag" should be idempotent, surely, and not a GET request?)

namaria · 2 years ago
I also feel that there's a growing need to teach fundamentals to people across the board. On the other hand, there doesn't seem to be any market for it. So many people become 'developers' by attending 90 days bootcamps to get a job quickly and so many more avoid anything technical altogether because they're 'not a technical person'. So I doubt there's any market for teaching these basics...
bemusedthrow75 · 2 years ago
> So I doubt there's any market for teaching these basics...

While working through the idea, the most challenging aspect for me has been how to describe the value of it, even though I know what the value of it is.

I think there are parallels, like no longer knowing what is going on under the hood of your car, which has its own anxieties.

Paradoxically I think it is non-programmers who are more interested in the kind of "history lessons" of it -- like, how did we end up here, 10,000 feet view stuff. And perhaps just a small amount of that would stop people being bamboozled by copy-and-paste nonsense in proposals, quotes, project plans etc.

It strikes me as interesting to think about, that if you were to go back in time and ask someone twenty years ago if they knew much about the web, those people, who might be from diverse non-technical fields, might be able to tell you quite a lot they'd gleaned about how it actually works. Because the books on the web then taught you how it worked. Surprising people used to know about domain names and FTP servers.

But nowadays, the knowledge is much higher-level, and in a way that leads people into believing things only have complex dependencies, like React or serverless designs or Cloudflare.

It's like the web needs its own Raspberry Pi movement.