Live data from Hacker News

React is holding me hostage

emnudge.dev

121–130 of 553 posts

Re: React is holding me hostage

#121
post #81

> It is not obvious that your component re-renders on state updates. I... isn't it? Isn't this like the first thing in the hooks introductory material? If you don't find this, yeah, hooks are gonna be a bad time.

I went and checked, and it is a bit buried at the bottom of the useState explanation when explaining what an example does: > Line 9: When the user clicks, we call setCount with a new value. React will then re-render the Example component, passing the new count value to it. https://reactjs.org/docs/hooks-state.html I think they assume you'll figure out that it must do so to function at all.

This has been true even in the old class components. A component always updates when props update.

Re: React is holding me hostage

#122
post #50

Not to start an unholy flame war, but if you were to start a new project and didn’t need to worry about the ecosystem or workforce, what framework would you choose? Vue? Svelte? Something else?

I don't know about Vue3 (I used in the past Vue2 only), but Svelte is similar to React, I'm migrating a small/medium project from React to Svelte and it feels too easy most of the time to port component by component, also to me, at least to this point, Svelte feels more performant and you have 100% control over the reactivity without too much `use{function}`.

I would recommend you to build a small project, maybe a Todo app in every framework you want to try, or maybe if you have a project, build a small part of it in each (I will pick the part that you think is the trickiest to build with React or the framework you are actually using).

Also I'll recommend to also check Qwik and Fresh(deno).

Re: React is holding me hostage

#123
post #50

Not to start an unholy flame war, but if you were to start a new project and didn’t need to worry about the ecosystem or workforce, what framework would you choose? Vue? Svelte? Something else?

I just started one small project that is a single component that talks to our API and is rendered on an external website. I used lit-html for it. Very small, very fast library for this kind of thing. No build tool required. I choose my own (smaller, simpler, more straightforward) way of managing state.

Re: React is holding me hostage

#124
post #93

As a more backend guy who does some frontend, the main thing I like about React over alternatives like Svelte, Vue and SolidJS is React Native. React is maybe not perfect for the web, but it’s very, very good, and it’s also quite good for mobile via React Native. The more purely web-focused libs/frameworks have far inferior (or no) mobile options, while other cross-platform frameworks, like Flutter, suck on the web.…

There is also https://svelte-native.technology/ (and I suspect similar projects for other frameworks) though I haven't used any of the "* Native"s

Re: React is holding me hostage

#125
post #120

Earlier quoted context omitted.

> I'm not sure I'd ever expect a framework, React or anything else, to stop that behavior. Isn't this the whole selling point of Solid's signals? If a child component receives its props from the parent as signals, and asks the parent to fetch some data and update the state, then the child won't rerender; only the bits that are consuming the signals will. Fine-grained reactivity, they call it.

I saw signals in Preact and I thought the same.

The article goes into exactly this.

Re: React is holding me hostage

#126

Earlier quoted context omitted.

> All blow up events come from a loud and extremely small minority. But whether they are making noise or signal, does not depend on number of people! Fair, this instance is 100% noise imo. We're engineers - we should be able to judge when something is silly. > React continues to dominate others because it has corporate backing while Vue doesn't. And angular was popular for the same reason before angular 2. I have nev…

"Doesn't reinvent the wheel" they literally created a whole new language called JSX, I have 13 years writing JS and I dislike React and JSX is one of the reasons. As far I can tell reason it's picked a lot of times now it's market share, people see that is more popular than the competition so they try to learn it, creating a feedback loop that just makes it more popular.

I actually like JSX a lot, but I'm baffled when people act like the very thin DSL used by svelte is any more unapproachable than JSX, or like JSX is somehow more javascript when it's a mish-mash of extended HTML (don't forget to use key as needed, and className), React components, and JS (expressions only, not statements... and weird-looking ones at that)

Re: React is holding me hostage

#128

> When I build libraries for React, ironically, I don't really use hooks like useState, useReducer, etc. One of the best perks (and footguns) of managing your state outside of react is that you get to have full control over when a component should rerender. I don't understand this quote from Tanner. Aren't React hooks, like, the only way to tell a function React component (while inside of it) to re-render? And if you…

I really only have familiarity with React-query, but I'd guess it's something like:

While of course React-query plugs into the React lifecycle, it's also kind of an escape hatch that plays nice with React.

Managing the fetch function calls, their state, their resolutions, and the cache, all probably happens outside of React, but then changes to any of the query state are reflected into the React lifecycle.

This probably lets him do something like using localstorage for storing cached query data, communicating between tabs, etc

Re: React is holding me hostage

#130

Things get more complicated when you start using React Context and start signalling updates in a parent component. The render cascades. Maybe one component fetches some data, some component remounts, and you run your state update again, delayed by a few seconds. I'm not sure I'd ever expect a framework, React or anything else, to stop that behavior. If a child component signals to a parent that the state has changed…

> I'm not sure I'd ever expect a framework, React or anything else, to stop that behavior. Isn't this the whole selling point of Solid's signals? If a child component receives its props from the parent as signals, and asks the parent to fetch some data and update the state, then the child won't rerender; only the bits that are consuming the signals will. Fine-grained reactivity, they call it.

I've not used Solid much so I can't say, but my point is that if your app is rerendering unexpectedly that's because you haven't spend the time to think about the data flow around your app. It's possible, and not that hard even in a large app, to build things so that this doesn't happen. Signals sound like a way of avoiding updates, and if the experience of using them is elegant or if the performance is better that's awesome, but you definitely can build apps without them and never see the problem they solve.
Post reply on HN