News for hackers. Stuff that matters.
Re:Progressive React by timw4mail on Friday December 20, 2019 @07:21PM (#21848617)
The more I deal with it, the more I hate React, and the very idea that websites must require Javascript to just show HTML.
Re:Progressive React by sombremesa on Friday December 20, 2019 @07:28PM (#21848651)
Fear is the path to the dark side. Fear leads to anger. Anger leads to hate. Hate leads to suffering.

Jokes aside, everything has its place. You're still allowed to hate it though. For example, I hate Redux because everyone uses it for every React app and it's got boilerplate up the wazoo.

Just know that if you "hate" things, though, you won't learn as much in life, like I won't learn how to use time travel debugging. Almost anything that gets this popular has at least a few core ideas we should probably learn, or learn from.

Re:Progressive React by randomsearch on Friday December 20, 2019 @08:41PM (#21848998)
I’m not sure this is true. For example, what can I learn from JS that isn’t in better languages? In tech we have this weird situation where many things become popular without good reason. It’s ironic, because a group of people (nerds) who think they are the epitome of rationality are actually the opposite: we make very emotional decisions when we could be entirely rational, as we have access to data other fields do not.
Re:Progressive React by simongray on Friday December 20, 2019 @09:41PM (#21849254)
Frontend doesn't always mean using JS. You can use a well-designed, modern language like ClojureScript instead that isn't anything like using JS, yet nevertheless has the same access to the browser.
Re:Progressive React by austincheney on Friday December 20, 2019 @10:27PM (#21849398)
Well... there are only two standard APIs for the front end: DOM and the web API (browser stuff and HTML5 things). Once comfort with those is achieved you suddenly need so much less code to do radically more ambitious things.

The time saved in both authoring and maintenance pays for itself in learning the standards.

Re:Progressive React by sombremesa on Sunday December 22, 2019 @04:01PM (#21859635)
> For example, what can I learn from JS that isn’t in better languages?

I only said "at least a few core ideas" -- not, "at least a few unique core ideas". Sure there are other places you can learn the same things, which of course doesn't mean that JS is now somehow stripped of that value.

Re:Progressive React by sophiebits on Saturday December 21, 2019 @01:17AM (#21849925)
The web community has a focus on byte size which is rarely found anywhere else in application development.
Re:Progressive React by wolco on Friday December 20, 2019 @08:03PM (#21848830)
Is there a way to cutdown the bloat?
Re:Progressive React by munchbunny on Friday December 20, 2019 @08:32PM (#21848963)
Not in a substantial way. The boilerplate is a consequence of the functional “workaround”: representing a mutation as the result of applying a state transition to a complex state, and then computing what to display as a function of both the current and previous states.

The way to reduce the boilerplate is to use a mutable paradigm, but then you lose the simplifications that the immutable paradigm gives you.

Re:Progressive React by acemarke on Saturday December 21, 2019 @01:32AM (#21849965)
There's a fantastic library called Immer [0] that uses ES6 Proxies to let you write "mutative" update logic that is tracked and turned into a safe immutable update.

We recommend using Immer as the best way to write immutable logic with Redux [1], and our new Redux Toolkit package [2] automatically uses Immer internally to let you write reducers like this:

    const reducer = createReducer(initialState, {
      updateItem(state, action) {
        state.first.second[action.payload.id].fourth = action.payload.value
      }
    })

[0] https://immerjs.github.io/immer/

[1] https://redux.js.org/style-guide/style-guide/#use-immer-for-...

[2] https://redux-toolkit.js.org

Re:Progressive React by rictic on Friday December 20, 2019 @08:41PM (#21849002)
Check out lit-html. You write functional style code, but the library does efficient minimal mutations of the dom with no virtual dom, and no dom diffing.
Re:Progressive React by Richicoder on Friday December 20, 2019 @08:37PM (#21848982)
I'd recommend checkout out Redux Toolkit and reading over the docs. Severely cuts down the boilerplate, but still walks you through the general ideas and fundamentals in a great way.
Re:Progressive React by duxup on Friday December 20, 2019 @08:47PM (#21849026)
If all you want to do is serve up HTML... you don't pick react.
Re:Progressive React by wldlyinaccurate on Saturday December 21, 2019 @05:57AM (#21850727)
I've used React as a server-side templating language on many projects small and large. The main feature that makes React great for rendering HTML is higher-order components. In my experience any project of sufficient complexity starts to get ugly with a "regular" templating language. React encourages composition of small isolated components, which tends to result in code that is easier to understand and maintain.

Admittedly this works best on projects that don't require a massively complex interactive front-end, like news sites[0] and data reporting tools. But at some point you can just choose to start hydrating the interactive components in the browser without changing your back-end setup at all.

[0]: https://wildlyinaccurate.com/introducing-a-faster-bbc-news-f...

Re:Progressive React by duxup on Saturday December 21, 2019 @08:39AM (#21851143)
Yeah that's totally true.

Really everything is delivering HTML ... and maybe something else.

I was thinking in the simplest form as the person I was responding to seemed to be saying that just to do something ultra basic react was not something they liked.

Re:Progressive React by fake-name on Saturday December 21, 2019 @02:18AM (#21850117)
Yeah, now if only people actually did that.
Re:Progressive React by qwerty1234599 on Saturday December 21, 2019 @06:59AM (#21850878)
React isn't used for webSITES. It's used for web applications.
Re:Progressive React by timw4mail on Saturday December 21, 2019 @08:48AM (#21851162)
Hah, I wish.
Re:Progressive React by duxup on Saturday December 21, 2019 @08:56AM (#21851192)
It's a choice really.

There's ways to do a lot of things (I swear that is the real sticking point on HN when it comes to react discussions).

But just serving up straight HTML, you could actually use react, but you don't have to do it "just" to do that.

If you're stuck in a spot where you HAVE to use it, that's the fault of whomever decided that, not react.