Settings

Theme

React Considered Harmful

werkema.com

1 points by lupin_sansei 6 years ago · 1 comment

Reader

testbot123 6 years ago

This is somewhat disingenuous. They give the simple example below:

  $(".fooButton").click(function() {
      $.ajax("/update-foos", { method: "POST" });
  });
and then give the "same" example the React treatment, which not only includes third party libraries for fetching, but also managing fetch state, storing data, and connecting to the store, which none of the above does.

A better version of React doing the above would be:

  export function FetchDataButton ({ ...buttonProps }) {
    const fetchData = useCallback(() => fetch('/update-foos', {method: 'POST'}), [])
    // prop drilling for this example only. don't do this normally.
    return <button {...buttonProps} onClick={fetchData} />
  }
which does exactly what the initial example does, additionally rendering the actual button, built-in DOM reconciliation, a declarative API, built-in reactivity (meaning you don't have to handle figuring out what gets updated in response to new data), etc etc.

Yes, React introduces boilerplate but not as much as this post makes out, and certainly not enough to warrant the "considered harmful" label.

> We — all of us — are not mature enough yet for abstractions like React.

Not quite. You aren't ready because you haven't learned the basic concepts enough to understand the problems that React is solving.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection